lkml.org 
[lkml]   [2023]   [May]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2 1/2] crypto: hisilicon - Add HiSilicon ADVCA Subsystem
From
Date
Hi David,

On Sa, 2023-05-13 at 15:43 +0800, David Yang wrote:
> HiSilicon ADVCA Subsystem contains various cryptographic devices, including
> symmetric key ciphers, hash functions, RSA algorithms, as well as key
> ladder and OTP memory.
>
> This patch adds symmetric key cipher driver.
>
> Signed-off-by: David Yang <mmyangfl@gmail.com>
> ---
>  drivers/crypto/hisilicon/Kconfig | 8 +
>  drivers/crypto/hisilicon/Makefile | 1 +
>  drivers/crypto/hisilicon/advca/Makefile | 1 +
>  .../crypto/hisilicon/advca/hisi-advca-muc.c | 1527 +++++++++++++++++
>  4 files changed, 1537 insertions(+)
>  create mode 100644 drivers/crypto/hisilicon/advca/Makefile
>  create mode 100644 drivers/crypto/hisilicon/advca/hisi-advca-muc.c
>
[...]
> diff --git a/drivers/crypto/hisilicon/advca/hisi-advca-muc.c b/drivers/crypto/hisilicon/advca/hisi-advca-muc.c
> new file mode 100644
> index 000000000000..362596a91e19
> --- /dev/null
> +++ b/drivers/crypto/hisilicon/advca/hisi-advca-muc.c
> @@ -0,0 +1,1527 @@
[...]
> +static int hica_muc_probe(struct platform_device *pdev)
> +{
[...]
> + priv->rst = devm_reset_control_get_optional(dev, NULL);

Please use devm_reset_control_get_optional_exclusive() directly.

Since priv->rst is only ever used in hica_muc_probe(), it could be
stored in a local variable instead.

> + if (IS_ERR(priv->rst))
> + return PTR_ERR(priv->rst);
> +
> + ret = platform_get_irq(pdev, 0);
> + if (ret < 0)
> + return ret;
> + priv->irqs[0] = ret;
> + priv->irqs[1] = platform_get_irq_optional(pdev, 1);
> +
> + priv->algs_num = ARRAY_SIZE(hica_muc_tmpls);
> + priv->algs = devm_kmalloc_array(dev, priv->algs_num,
> + sizeof(priv->algs[0]), GFP_KERNEL);
> + if (!priv->algs)
> + return -ENOMEM;
> +
> + init_completion(&priv->cond);
> +
> + priv->dev = dev;
> + platform_set_drvdata(pdev, priv);
> + dev_set_drvdata(dev, priv);
> +
> + /* bring up device */
> + ret = reset_control_assert(priv->rst) ?:
> + clk_bulk_prepare_enable(priv->clks_num, priv->clks) ?:
> + reset_control_deassert(priv->rst);

Using the ternary operator like this is a bit unconventional. Here, the
clocks are kept enabled if the reset_control_deassert() fails.

It would be good to add an error path that disables the clocks.

> + if (ret)
> + return ret;
> +
> + if (!(readl(priv->base + MUC_RST_STATUS) & MUC_STATE_VALID)) {
> + msleep(20);
> + if (!(readl(priv->base + MUC_RST_STATUS) & MUC_STATE_VALID)) {
> + dev_err(dev, "cannot bring up device\n");
> + return -ENODEV;

This also leaves the clocks enabled. There are some more return
statements with the same issue below.

regards
Philipp

\
 
 \ /
  Last update: 2023-05-24 12:46    [W:0.186 / U:0.472 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site