2018-01-18 21:14:43

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] irq-imx-gpcv2: Adjustments for imx_gpcv2_irqchip_init()

From: Markus Elfring <[email protected]>
Date: Thu, 18 Jan 2018 22:08:44 +0100

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Delete an error message for a failed memory allocation
Improve a size determination
Use common error handling code

drivers/irqchip/irq-imx-gpcv2.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

--
2.15.1



2018-01-18 21:17:08

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] irq-imx-gpcv2: Delete an error message for a failed memory allocation in imx_gpcv2_irqchip_init()

From: Markus Elfring <[email protected]>
Date: Thu, 18 Jan 2018 21:23:06 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/irqchip/irq-imx-gpcv2.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/irqchip/irq-imx-gpcv2.c b/drivers/irqchip/irq-imx-gpcv2.c
index 675eda5ff2b8..f08fcbb46b1b 100644
--- a/drivers/irqchip/irq-imx-gpcv2.c
+++ b/drivers/irqchip/irq-imx-gpcv2.c
@@ -225,10 +225,8 @@ static int __init imx_gpcv2_irqchip_init(struct device_node *node,
}

cd = kzalloc(sizeof(struct gpcv2_irqchip_data), GFP_KERNEL);
- if (!cd) {
- pr_err("kzalloc failed!\n");
+ if (!cd)
return -ENOMEM;
- }

raw_spin_lock_init(&cd->rlock);

--
2.15.1


2018-01-18 21:17:21

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] irq-imx-gpcv2: Improve a size determination in imx_gpcv2_irqchip_init()

From: Markus Elfring <[email protected]>
Date: Thu, 18 Jan 2018 21:25:13 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/irqchip/irq-imx-gpcv2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/irq-imx-gpcv2.c b/drivers/irqchip/irq-imx-gpcv2.c
index f08fcbb46b1b..e62f22c84112 100644
--- a/drivers/irqchip/irq-imx-gpcv2.c
+++ b/drivers/irqchip/irq-imx-gpcv2.c
@@ -224,7 +224,7 @@ static int __init imx_gpcv2_irqchip_init(struct device_node *node,
return -ENXIO;
}

- cd = kzalloc(sizeof(struct gpcv2_irqchip_data), GFP_KERNEL);
+ cd = kzalloc(sizeof(*cd), GFP_KERNEL);
if (!cd)
return -ENOMEM;

--
2.15.1


2018-01-18 21:19:42

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] irq-imx-gpcv2: Use common error handling code in imx_gpcv2_irqchip_init()

From: Markus Elfring <[email protected]>
Date: Thu, 18 Jan 2018 22:00:05 +0100

Add a jump target so that a bit of exception handling can be better reused
at the end of this function.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/irqchip/irq-imx-gpcv2.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/irqchip/irq-imx-gpcv2.c b/drivers/irqchip/irq-imx-gpcv2.c
index e62f22c84112..2dc348581877 100644
--- a/drivers/irqchip/irq-imx-gpcv2.c
+++ b/drivers/irqchip/irq-imx-gpcv2.c
@@ -233,16 +233,14 @@ static int __init imx_gpcv2_irqchip_init(struct device_node *node,
cd->gpc_base = of_iomap(node, 0);
if (!cd->gpc_base) {
pr_err("fsl-gpcv2: unable to map gpc registers\n");
- kfree(cd);
- return -ENOMEM;
+ goto free_data;
}

domain = irq_domain_add_hierarchy(parent_domain, 0, GPC_MAX_IRQS,
node, &gpcv2_irqchip_data_domain_ops, cd);
if (!domain) {
iounmap(cd->gpc_base);
- kfree(cd);
- return -ENOMEM;
+ goto free_data;
}
irq_set_default_host(domain);

@@ -272,6 +270,10 @@ static int __init imx_gpcv2_irqchip_init(struct device_node *node,
*/
of_node_clear_flag(node, OF_POPULATED);
return 0;
+
+free_data:
+ kfree(cd);
+ return -ENOMEM;
}

IRQCHIP_DECLARE(imx_gpcv2, "fsl,imx7d-gpc", imx_gpcv2_irqchip_init);
--
2.15.1