All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] irqchip/mbigen: move to use bus_get_dev_root()
@ 2023-05-04  7:34 Dan Carpenter
  2023-05-04 11:56 ` Kefeng Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2023-05-04  7:34 UTC (permalink / raw)
  To: gregkh; +Cc: Kefeng Wang, Hanjun Guo, Ma Jun, Ming Lei, kernel-janitors

Hello Greg Kroah-Hartman,

The patch fea087fc291b: "irqchip/mbigen: move to use
bus_get_dev_root()" from Mar 13, 2023, leads to the following Smatch
static checker warning:

	drivers/irqchip/irq-mbigen.c:258 mbigen_of_create_domain()
	error: potentially dereferencing uninitialized 'child'.

drivers/irqchip/irq-mbigen.c
    235 static int mbigen_of_create_domain(struct platform_device *pdev,
    236                                    struct mbigen_device *mgn_chip)
    237 {
    238         struct device *parent;
    239         struct platform_device *child;
    240         struct irq_domain *domain;
    241         struct device_node *np;
    242         u32 num_pins;
    243 
    244         for_each_child_of_node(pdev->dev.of_node, np) {
    245                 if (!of_property_read_bool(np, "interrupt-controller"))
    246                         continue;
    247 
    248                 parent = bus_get_dev_root(&platform_bus_type);
    249                 if (parent) {

Smatch is concerned that "parent" can be NULL.  Probably unlikely in
real life.

    250                         child = of_platform_device_create(np, NULL, parent);
    251                         put_device(parent);
    252                         if (!child) {
    253                                 of_node_put(np);
    254                                 return -ENOMEM;
    255                         }
    256                 }
    257 
--> 258                 if (of_property_read_u32(child->dev.of_node, "num-pins",
    259                                          &num_pins) < 0) {
    260                         dev_err(&pdev->dev, "No num-pins property\n");
    261                         of_node_put(np);
    262                         return -EINVAL;
    263                 }
    264 
    265                 domain = platform_msi_create_device_domain(&child->dev, num_pins,
    266                                                            mbigen_write_msg,
    267                                                            &mbigen_domain_ops,
    268                                                            mgn_chip);
    269                 if (!domain) {
    270                         of_node_put(np);
    271                         return -ENOMEM;
    272                 }
    273         }
    274 
    275         return 0;
    276 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [bug report] irqchip/mbigen: move to use bus_get_dev_root()
  2023-05-04  7:34 [bug report] irqchip/mbigen: move to use bus_get_dev_root() Dan Carpenter
@ 2023-05-04 11:56 ` Kefeng Wang
  2023-05-04 14:46   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Kefeng Wang @ 2023-05-04 11:56 UTC (permalink / raw)
  To: Dan Carpenter, gregkh; +Cc: Hanjun Guo, Ma Jun, Ming Lei, kernel-janitors



On 2023/5/4 15:34, Dan Carpenter wrote:
> Hello Greg Kroah-Hartman,
> 
> The patch fea087fc291b: "irqchip/mbigen: move to use
> bus_get_dev_root()" from Mar 13, 2023, leads to the following Smatch
> static checker warning:
> 
> 	drivers/irqchip/irq-mbigen.c:258 mbigen_of_create_domain()
> 	error: potentially dereferencing uninitialized 'child'.
> 
> drivers/irqchip/irq-mbigen.c
>      235 static int mbigen_of_create_domain(struct platform_device *pdev,
>      236                                    struct mbigen_device *mgn_chip)
>      237 {
>      238         struct device *parent;
>      239         struct platform_device *child;
>      240         struct irq_domain *domain;
>      241         struct device_node *np;
>      242         u32 num_pins;
>      243
>      244         for_each_child_of_node(pdev->dev.of_node, np) {
>      245                 if (!of_property_read_bool(np, "interrupt-controller"))
>      246                         continue;
>      247
>      248                 parent = bus_get_dev_root(&platform_bus_type);
>      249                 if (parent) {
> 
> Smatch is concerned that "parent" can be NULL.  Probably unlikely in
> real life.

How about move bus_get_dev_root() out of the loop.

diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c
index eada5e0e3eb9..954a55ed1f2b 100644
--- a/drivers/irqchip/irq-mbigen.c
+++ b/drivers/irqchip/irq-mbigen.c
@@ -240,26 +240,25 @@ static int mbigen_of_create_domain(struct 
platform_device *pdev,
  	struct irq_domain *domain;
  	struct device_node *np;
  	u32 num_pins;
+	int ret = -ENODEV;
+
+	parent = bus_get_dev_root(&platform_bus_type);
+	if (!parent)
+		return ret;

  	for_each_child_of_node(pdev->dev.of_node, np) {
  		if (!of_property_read_bool(np, "interrupt-controller"))
  			continue;

-		parent = bus_get_dev_root(&platform_bus_type);
-		if (parent) {
-			child = of_platform_device_create(np, NULL, parent);
-			put_device(parent);
-			if (!child) {
-				of_node_put(np);
-				return -ENOMEM;
-			}
-		}
+		child = of_platform_device_create(np, NULL, parent);
+		if (!child)
+			goto out_put;

  		if (of_property_read_u32(child->dev.of_node, "num-pins",
  					 &num_pins) < 0) {
  			dev_err(&pdev->dev, "No num-pins property\n");
-			of_node_put(np);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto out_put;
  		}

  		domain = platform_msi_create_device_domain(&child->dev, num_pins,
@@ -267,12 +266,17 @@ static int mbigen_of_create_domain(struct 
platform_device *pdev,
  							   &mbigen_domain_ops,
  							   mgn_chip);
  		if (!domain) {
-			of_node_put(np);
-			return -ENOMEM;
+			ret = -ENOMEM;
+			goto out_put;
  		}
  	}

  	return 0;
+
+out_put:
+	of_node_put(np);
+	put_device(parent);
+	return ret;
  }




> 
> regards,
> dan carpenter

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [bug report] irqchip/mbigen: move to use bus_get_dev_root()
  2023-05-04 11:56 ` Kefeng Wang
@ 2023-05-04 14:46   ` Dan Carpenter
  2023-05-05  8:55     ` Kefeng Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2023-05-04 14:46 UTC (permalink / raw)
  To: Kefeng Wang; +Cc: gregkh, Hanjun Guo, Ma Jun, Ming Lei, kernel-janitors

On Thu, May 04, 2023 at 07:56:07PM +0800, Kefeng Wang wrote:
> 
> 
> On 2023/5/4 15:34, Dan Carpenter wrote:
> > Hello Greg Kroah-Hartman,
> > 
> > The patch fea087fc291b: "irqchip/mbigen: move to use
> > bus_get_dev_root()" from Mar 13, 2023, leads to the following Smatch
> > static checker warning:
> > 
> > 	drivers/irqchip/irq-mbigen.c:258 mbigen_of_create_domain()
> > 	error: potentially dereferencing uninitialized 'child'.
> > 
> > drivers/irqchip/irq-mbigen.c
> >      235 static int mbigen_of_create_domain(struct platform_device *pdev,
> >      236                                    struct mbigen_device *mgn_chip)
> >      237 {
> >      238         struct device *parent;
> >      239         struct platform_device *child;
> >      240         struct irq_domain *domain;
> >      241         struct device_node *np;
> >      242         u32 num_pins;
> >      243
> >      244         for_each_child_of_node(pdev->dev.of_node, np) {
> >      245                 if (!of_property_read_bool(np, "interrupt-controller"))
> >      246                         continue;
> >      247
> >      248                 parent = bus_get_dev_root(&platform_bus_type);
> >      249                 if (parent) {
> > 
> > Smatch is concerned that "parent" can be NULL.  Probably unlikely in
> > real life.
> 
> How about move bus_get_dev_root() out of the loop.
> 

Sounds good to me, but I don't know this code at all.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [bug report] irqchip/mbigen: move to use bus_get_dev_root()
  2023-05-04 14:46   ` Dan Carpenter
@ 2023-05-05  8:55     ` Kefeng Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Kefeng Wang @ 2023-05-05  8:55 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: gregkh, Ming Lei, kernel-janitors, Hanjun Guo



On 2023/5/4 22:46, Dan Carpenter wrote:
> On Thu, May 04, 2023 at 07:56:07PM +0800, Kefeng Wang wrote:
>>
>>
>> On 2023/5/4 15:34, Dan Carpenter wrote:
>>> Hello Greg Kroah-Hartman,
>>>
>>> The patch fea087fc291b: "irqchip/mbigen: move to use
>>> bus_get_dev_root()" from Mar 13, 2023, leads to the following Smatch
>>> static checker warning:
>>>
>>> 	drivers/irqchip/irq-mbigen.c:258 mbigen_of_create_domain()
>>> 	error: potentially dereferencing uninitialized 'child'.
>>>
>>> drivers/irqchip/irq-mbigen.c
>>>       235 static int mbigen_of_create_domain(struct platform_device *pdev,
>>>       236                                    struct mbigen_device *mgn_chip)
>>>       237 {
>>>       238         struct device *parent;
>>>       239         struct platform_device *child;
>>>       240         struct irq_domain *domain;
>>>       241         struct device_node *np;
>>>       242         u32 num_pins;
>>>       243
>>>       244         for_each_child_of_node(pdev->dev.of_node, np) {
>>>       245                 if (!of_property_read_bool(np, "interrupt-controller"))
>>>       246                         continue;
>>>       247
>>>       248                 parent = bus_get_dev_root(&platform_bus_type);
>>>       249                 if (parent) {
>>>
>>> Smatch is concerned that "parent" can be NULL.  Probably unlikely in
>>> real life.
>>
>> How about move bus_get_dev_root() out of the loop.
>>
> 
> Sounds good to me, but I don't know this code at all.
Post a patch[1], let's wait for review, and could you help to test it,
man thanks.

[1] 
https://lore.kernel.org/all/20230505090654.12793-1-wangkefeng.wang@huawei.com/
> 
> regards,
> dan carpenter
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-05  8:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04  7:34 [bug report] irqchip/mbigen: move to use bus_get_dev_root() Dan Carpenter
2023-05-04 11:56 ` Kefeng Wang
2023-05-04 14:46   ` Dan Carpenter
2023-05-05  8:55     ` Kefeng Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.