diff mbox series

crypto: Hold the reference returned by of_find_compatible_node

Message ID 20220621073742.4081013-1-windhl@126.com (mailing list archive)
State Changes Requested
Delegated to: Herbert Xu
Headers show
Series crypto: Hold the reference returned by of_find_compatible_node | expand

Commit Message

Liang He June 21, 2022, 7:37 a.m. UTC
In nx842_pseries_init() and crypto4xx_probe(), we should hold the
reference returned by of_find_compatible_node() and use it to call
of_node_put to keep refcount balance.

Signed-off-by: Liang He <windhl@126.com>
---
 drivers/crypto/amcc/crypto4xx_core.c  | 13 ++++++++-----
 drivers/crypto/nx/nx-common-pseries.c |  5 ++++-
 2 files changed, 12 insertions(+), 6 deletions(-)

Comments

Herbert Xu June 30, 2022, 6:43 a.m. UTC | #1
Liang He <windhl@126.com> wrote:
> In nx842_pseries_init() and crypto4xx_probe(), we should hold the
> reference returned by of_find_compatible_node() and use it to call
> of_node_put to keep refcount balance.
> 
> Signed-off-by: Liang He <windhl@126.com>
> ---
> drivers/crypto/amcc/crypto4xx_core.c  | 13 ++++++++-----
> drivers/crypto/nx/nx-common-pseries.c |  5 ++++-
> 2 files changed, 12 insertions(+), 6 deletions(-)

Please split this into two patches.

> diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
> index 8278d98074e9..169b6a05e752 100644
> --- a/drivers/crypto/amcc/crypto4xx_core.c
> +++ b/drivers/crypto/amcc/crypto4xx_core.c
> @@ -1378,6 +1378,7 @@ static int crypto4xx_probe(struct platform_device *ofdev)
>        struct resource res;
>        struct device *dev = &ofdev->dev;
>        struct crypto4xx_core_device *core_dev;
> +       struct device_node *np;
>        u32 pvr;
>        bool is_revb = true;
> 
> @@ -1385,20 +1386,20 @@ static int crypto4xx_probe(struct platform_device *ofdev)
>        if (rc)
>                return -ENODEV;
> 
> -       if (of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) {
> +       if ((np = of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) != NULL) {

This is getting awkwardly long.  Please change this to

	np = ...;
	if (np) {

Thanks,
Liang He June 30, 2022, 6:46 a.m. UTC | #2
At 2022-06-30 14:43:21, "Herbert Xu" <herbert@gondor.apana.org.au> wrote:
>Liang He <windhl@126.com> wrote:
>> In nx842_pseries_init() and crypto4xx_probe(), we should hold the
>> reference returned by of_find_compatible_node() and use it to call
>> of_node_put to keep refcount balance.
>> 
>> Signed-off-by: Liang He <windhl@126.com>
>> ---
>> drivers/crypto/amcc/crypto4xx_core.c  | 13 ++++++++-----
>> drivers/crypto/nx/nx-common-pseries.c |  5 ++++-
>> 2 files changed, 12 insertions(+), 6 deletions(-)
>
>Please split this into two patches.
>

OK.

>> diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
>> index 8278d98074e9..169b6a05e752 100644
>> --- a/drivers/crypto/amcc/crypto4xx_core.c
>> +++ b/drivers/crypto/amcc/crypto4xx_core.c
>> @@ -1378,6 +1378,7 @@ static int crypto4xx_probe(struct platform_device *ofdev)
>>        struct resource res;
>>        struct device *dev = &ofdev->dev;
>>        struct crypto4xx_core_device *core_dev;
>> +       struct device_node *np;
>>        u32 pvr;
>>        bool is_revb = true;
>> 
>> @@ -1385,20 +1386,20 @@ static int crypto4xx_probe(struct platform_device *ofdev)
>>        if (rc)
>>                return -ENODEV;
>> 
>> -       if (of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) {
>> +       if ((np = of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) != NULL) {
>
>This is getting awkwardly long.  Please change this to
>
>	np = ...;
>	if (np) {
>
>Thanks,
>-- 
>Email: Herbert Xu <herbert@gondor.apana.org.au>
>Home Page: http://gondor.apana.org.au/~herbert/
>PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Thanks, Herbert.

I will resend two patches with above change.

Liang
diff mbox series

Patch

diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 8278d98074e9..169b6a05e752 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1378,6 +1378,7 @@  static int crypto4xx_probe(struct platform_device *ofdev)
 	struct resource res;
 	struct device *dev = &ofdev->dev;
 	struct crypto4xx_core_device *core_dev;
+	struct device_node *np;
 	u32 pvr;
 	bool is_revb = true;
 
@@ -1385,20 +1386,20 @@  static int crypto4xx_probe(struct platform_device *ofdev)
 	if (rc)
 		return -ENODEV;
 
-	if (of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) {
+	if ((np = of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) != NULL) {
 		mtdcri(SDR0, PPC460EX_SDR0_SRST,
 		       mfdcri(SDR0, PPC460EX_SDR0_SRST) | PPC460EX_CE_RESET);
 		mtdcri(SDR0, PPC460EX_SDR0_SRST,
 		       mfdcri(SDR0, PPC460EX_SDR0_SRST) & ~PPC460EX_CE_RESET);
-	} else if (of_find_compatible_node(NULL, NULL,
-			"amcc,ppc405ex-crypto")) {
+	} else if ((np = of_find_compatible_node(NULL, NULL,
+			"amcc,ppc405ex-crypto")) != NULL) {
 		mtdcri(SDR0, PPC405EX_SDR0_SRST,
 		       mfdcri(SDR0, PPC405EX_SDR0_SRST) | PPC405EX_CE_RESET);
 		mtdcri(SDR0, PPC405EX_SDR0_SRST,
 		       mfdcri(SDR0, PPC405EX_SDR0_SRST) & ~PPC405EX_CE_RESET);
 		is_revb = false;
-	} else if (of_find_compatible_node(NULL, NULL,
-			"amcc,ppc460sx-crypto")) {
+	} else if ((np = of_find_compatible_node(NULL, NULL,
+			"amcc,ppc460sx-crypto")) != NULL) {
 		mtdcri(SDR0, PPC460SX_SDR0_SRST,
 		       mfdcri(SDR0, PPC460SX_SDR0_SRST) | PPC460SX_CE_RESET);
 		mtdcri(SDR0, PPC460SX_SDR0_SRST,
@@ -1408,6 +1409,8 @@  static int crypto4xx_probe(struct platform_device *ofdev)
 		return -EINVAL;
 	}
 
+	of_node_put(np);
+
 	core_dev = kzalloc(sizeof(struct crypto4xx_core_device), GFP_KERNEL);
 	if (!core_dev)
 		return -ENOMEM;
diff --git a/drivers/crypto/nx/nx-common-pseries.c b/drivers/crypto/nx/nx-common-pseries.c
index 7584a34ba88c..3ea334b7f820 100644
--- a/drivers/crypto/nx/nx-common-pseries.c
+++ b/drivers/crypto/nx/nx-common-pseries.c
@@ -1208,10 +1208,13 @@  static struct vio_driver nx842_vio_driver = {
 static int __init nx842_pseries_init(void)
 {
 	struct nx842_devdata *new_devdata;
+	struct device_node *np;
 	int ret;
 
-	if (!of_find_compatible_node(NULL, NULL, "ibm,compression"))
+	np = of_find_compatible_node(NULL, NULL, "ibm,compression");
+	if (!np)
 		return -ENODEV;
+	of_node_put(np);
 
 	RCU_INIT_POINTER(devdata, NULL);
 	new_devdata = kzalloc(sizeof(*new_devdata), GFP_KERNEL);