mfd/omap-usb-tll: Adjustments for usbtll_omap_probe()
Subsystems (3)
cover mfd/omap-usb-tll: Adjustments for usbtll_omap_probe()
From: Markus Elfring <[email protected]>
Date: Mon, 15 Jan 2018 14:09:28 +0100
Three update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Delete two error messages for a failed memory allocation Improve a size determination
Return an error code only as a constant
drivers/mfd/omap-usb-tll.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
Signature · 1 line
2.15.1
PATCH 1/3 mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
From: Markus Elfring <[email protected]>
Date: Mon, 15 Jan 2018 13:39:25 +0100
Omit extra messages for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- drivers/mfd/omap-usb-tll.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -4
@@ -222,10 +222,8 @@ static int usbtll_omap_probe(struct platform_device *pdev)dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); -if (!tll) { -dev_err (dev,"Memory allocation failed\n" ); +if (!tll)return -ENOMEM ; - } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); tll->base =devm_ioremap_resource (dev, res);
@@ -258,7 +256,6 @@ static int usbtll_omap_probe(struct platform_device *pdev) GFP_KERNEL);if (!tll->ch_clk) { ret = -ENOMEM ; -dev_err (dev,"Couldn't allocate memory for channel clocks\n" ); goto err_clk_alloc; }
Signature · 1 line
2.15.1
PATCH 2/3 mfd/omap-usb-tll: Improve a size determination in usbtll_omap_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 15 Jan 2018 13:43:53 +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.
--- drivers/mfd/omap-usb-tll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mfd/omap-usb-tll.c +1 -2
@@ -220,8 +220,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)int i, ver;dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); - - tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); + tll =devm_kzalloc (dev,sizeof (*tll),GFP_KERNEL );if (!tll)return -ENOMEM ;
Signature · 1 line
2.15.1
PATCH 3/3 mfd/omap-usb-tll: Return an error code only as a constant in usbtll_omap_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 15 Jan 2018 14:00:45 +0100
* Return an error code without storing it in an intermediate variable.
* Delete the label "err_clk_alloc" and local variable "ret" which became unnecessary with this refactoring.
--- drivers/mfd/omap-usb-tll.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/mfd/omap-usb-tll.c +3 -9
@@ -216,7 +216,6 @@ static int usbtll_omap_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct resource *res;struct usbtll_omap *tll; -int ret =0 ;int i, ver;dev_dbg (dev,"starting TI HSUSB TLL Controller\n" );
@@ -254,8 +253,9 @@ static int usbtll_omap_probe(struct platform_device *pdev) tll->ch_clk =devm_kzalloc (dev,sizeof (struct clk *) * tll->nch,GFP_KERNEL );if (!tll->ch_clk) { - ret = -ENOMEM ; - goto err_clk_alloc; +pm_runtime_put_sync (dev); +pm_runtime_disable (dev); +return -ENOMEM ; }for (i =0 ; i < tll->nch; i++) {
@@ -278,12 +278,6 @@ static int usbtll_omap_probe(struct platform_device *pdev)spin_unlock (&tll_lock);return 0 ; - -err_clk_alloc: -pm_runtime_put_sync (dev); -pm_runtime_disable (dev); - -return ret; }/**
Signature · 1 line
2.15.1
Re: [PATCH 1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
In reply to SF Markus ElfringMarcus,
Quoted 26 lines · SF Markus Elfring
Omit extra messages 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/mfd/omap-usb-tll.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/mfd/omap-usb-tll.c +1
-3@@ -222,10 +222,8 @@ static int usbtll_omap_probe(struct platform_device *pdev)dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); -if (!tll) { -dev_err (dev,"Memory allocation failed\n" ); +if (!tll)return -ENOMEM ; - } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); tll->base =devm_ioremap_resource (dev, res);
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 4 lines
drivers/mfd/omap-usb-tll.c +0
-1@@ -258,7 +256,6 @@ static int usbtll_omap_probe(struct platform_device *pdev) GFP_KERNEL);if (!tll->ch_clk) { ret = -ENOMEM ; -dev_err (dev,"Couldn't allocate memory for channel clocks\n" );
I'd either leave this one, just to know which allocation failed or better use something like this (it is pseudo patch only, just to show idea):
drivers/mfd/omap-usb-tll.c +16 -23
@@ -108,9 +108,9 @@ (x) != OMAP_EHCI_PORT_MODE_PHY)struct usbtll_omap { -int nch;/* num. of channels */ -struct clk **ch_clk;void __iomem *base; +int nch;/* num. of channels */ +struct clk ch_clk[0 ]; };/*-------------------------------------------------------------------------*/
@@ -221,18 +221,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); - tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); -if (!tll) { -dev_err (dev,"Memory allocation failed\n" ); -return -ENOMEM ; - } - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - tll->base =devm_ioremap_resource (dev, res); -if (IS_ERR (tll->base)) -return PTR_ERR (tll->base); + base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); -platform_set_drvdata (pdev, tll);pm_runtime_enable (dev);pm_runtime_get_sync (dev);
@@ -240,27 +233,27 @@ static int usbtll_omap_probe(struct platform_device *pdev)switch (ver) {case OMAP_USBTLL_REV1 :case OMAP_USBTLL_REV4 : - tll->nch =OMAP_TLL_CHANNEL_COUNT ; + num =OMAP_TLL_CHANNEL_COUNT ;break ;case OMAP_USBTLL_REV2 :case OMAP_USBTLL_REV3 : - tll->nch =OMAP_REV2_TLL_CHANNEL_COUNT ; + num =OMAP_REV2_TLL_CHANNEL_COUNT ;break ;default : - tll->nch =OMAP_TLL_CHANNEL_COUNT ; + num =OMAP_TLL_CHANNEL_COUNT ;dev_dbg (dev,"USB TLL Rev : 0x%x not recognized, assuming %d channels\n" , - ver, tll->nch); + ver, num);break ; } - tll->ch_clk =devm_kzalloc (dev,sizeof (struct clk *) * tll->nch, -GFP_KERNEL ); -if (!tll->ch_clk) { - ret = -ENOMEM ; -dev_err (dev,"Couldn't allocate memory for channel clocks\n" ); - goto err_clk_alloc; - } + tll = devm_kzalloc(dev, sizeof(struct usbtll_omap) + (num * sizeof(...)), GFP_KERNEL); + if (!tll) + return -ENOMEM; + + tll->nch = num; + tll->base = base; + platform_set_drvdata(pdev, tll); for (i = 0; i < tll->nch; i++) { char clkname[] = "usb_tll_hs_usb_chx_clk";
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 260
Quoted 2 lines
drivers/mfd/omap-usb-tll.c +0
-0goto err_clk_alloc; }
What do you think? I'll prepare proper patch in case there's an agreement on above approach.
Best regards,
ladis
Re: [PATCH 1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Hi Ladislav,
Quoted 42 lines · Ladislav Michl
Marcus,
Quoted 26 lines · SF Markus Elfring
Omit extra messages 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/mfd/omap-usb-tll.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/mfd/omap-usb-tll.c +1
-3@@ -222,10 +222,8 @@ static int usbtll_omap_probe(struct platform_device *pdev)dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); -if (!tll) { -dev_err (dev,"Memory allocation failed\n" ); +if (!tll)return -ENOMEM ; - } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); tll->base =devm_ioremap_resource (dev, res);drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 4 lines
drivers/mfd/omap-usb-tll.c +0
-1@@ -258,7 +256,6 @@ static int usbtll_omap_probe(struct platform_device *pdev) GFP_KERNEL);if (!tll->ch_clk) { ret = -ENOMEM ; -dev_err (dev,"Couldn't allocate memory for channel clocks\n" );I'd either leave this one, just to know which allocation failed or better use something like this (it is pseudo patch only, just to show idea):
drivers/mfd/omap-usb-tll.c +0
-0
drivers/mfd/omap-usb-tll.c line 113
Quoted 8 lines
drivers/mfd/omap-usb-tll.c +2
-2@@ -108,9 +108,9 @@ (x) != OMAP_EHCI_PORT_MODE_PHY) struct usbtll_omap { - int nch; /* num. of channels */ - struct clk **ch_clk; void __iomem *base; + int nch; /* num. of channels */ + struct clk ch_clk[0];
How about putting a comment here that says ch_clk needs to be the last member of this structure?
Quoted 26 lines
drivers/mfd/omap-usb-tll.c +3
-10};/*-------------------------------------------------------------------------*/ @@ -221,18 +221,11 @@ static int usbtll_omap_probe(struct platform_device *pdev)dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); - tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); -if (!tll) { -dev_err (dev,"Memory allocation failed\n" ); -return -ENOMEM ; - } - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - tll->base =devm_ioremap_resource (dev, res); -if (IS_ERR (tll->base)) -return PTR_ERR (tll->base); + base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); -platform_set_drvdata (pdev, tll);pm_runtime_enable (dev);pm_runtime_get_sync (dev);
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 236
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +1
-1@@ -240,27 +233,27 @@ static int usbtll_omap_probe(struct platform_device *pdev)switch (ver) {case OMAP_USBTLL_REV1 :case OMAP_USBTLL_REV4 : - tll->nch =OMAP_TLL_CHANNEL_COUNT ; + num =OMAP_TLL_CHANNEL_COUNT ;
need to declare num. Maybe better call it nch instead?
Quoted 14 lines
drivers/mfd/omap-usb-tll.c +3
-3break ;case OMAP_USBTLL_REV2 :case OMAP_USBTLL_REV3 : - tll->nch =OMAP_REV2_TLL_CHANNEL_COUNT ; + num =OMAP_REV2_TLL_CHANNEL_COUNT ;break ;default : - tll->nch =OMAP_TLL_CHANNEL_COUNT ; + num =OMAP_TLL_CHANNEL_COUNT ;dev_dbg (dev,"USB TLL Rev : 0x%x not recognized, assuming %d channels\n" , - ver, tll->nch); + ver, num);break ;
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 250
Quoted 10 lines
drivers/mfd/omap-usb-tll.c +1
-7} - tll->ch_clk =devm_kzalloc (dev,sizeof (struct clk *) * tll->nch, -GFP_KERNEL ); -if (!tll->ch_clk) { - ret = -ENOMEM ; -dev_err (dev,"Couldn't allocate memory for channel clocks\n" ); - goto err_clk_alloc; - } + tll = devm_kzalloc(dev, sizeof(struct usbtll_omap) + (num * sizeof(...)), GFP_KERNEL);
num * sizeof(tll->ch_clk[0]) ?
Quoted 10 lines
drivers/mfd/omap-usb-tll.c +6
-0+if (!tll) +return -ENOMEM ; + + tll->nch = num; + tll->base = base; +platform_set_drvdata (pdev, tll);for (i =0 ; i < tll->nch; i++) {char clkname[] ="usb_tll_hs_usb_chx_clk" ;
Quoted 5 lines
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 260
Quoted 2 lines
drivers/mfd/omap-usb-tll.c +0
-0goto err_clk_alloc; }What do you think? I'll prepare proper patch in case there's an agreement on above approach.
I think it is a good approach.
Quoted 8 lines
Best regards,
ladis
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Re: [PATCH 1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
In reply to Ladislav MichlQuoted 8 lines
Review static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 5 lines
(quoted diff) +0
-1@@ -258,7 +256,6 @@ static int usbtll_omap_probe(struct platform_device *pdev) GFP_KERNEL); if (!tll->ch_clk) { ret = -ENOMEM; - dev_err(dev, "Couldn't allocate memory for channel clocks\n");I'd either leave this one, just to know which allocation failed or better use something like this …
Are you aware on the structure for a Linux allocation failure report?
Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Marcus,
Quoted 10 lines · SF Markus Elfring
Quoted 8 lines
Review static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 5 lines
(quoted diff) +0
-1@@ -258,7 +256,6 @@ static int usbtll_omap_probe(struct platform_device *pdev) GFP_KERNEL); if (!tll->ch_clk) { ret = -ENOMEM; - dev_err(dev, "Couldn't allocate memory for channel clocks\n");I'd either leave this one, just to know which allocation failed or better use something like this …
Are you aware on the structure for a Linux allocation failure report?
Just created one (not OMAP and not this driver, but that does not matter now):
------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at mm/slab_common.c:1012 kmalloc_slab+0x38/0xdc Modules linked in: CPU: 0 PID: 1 Comm: swapper Not tainted 4.15.0-rc7-next-20180115 #25 Hardware name: Atmel AT91SAM9 [<c0107950>] (unwind_backtrace) from [<c010565c>] (show_stack+0x10/0x14) [<c010565c>] (show_stack) from [<c010f6cc>] (__warn+0xcc/0xe4) [<c010f6cc>] (__warn) from [<c010f7a4>] (warn_slowpath_null+0x38/0x44) [<c010f7a4>] (warn_slowpath_null) from [<c018ef90>] (kmalloc_slab+0x38/0xdc) [<c018ef90>] (kmalloc_slab) from [<c01a5494>] (__kmalloc_track_caller+0xc/0xb0) [<c01a5494>] (__kmalloc_track_caller) from [<c02fe5a8>] (devm_kmalloc+0x1c/0x58) [<c02fe5a8>] (devm_kmalloc) from [<c03f96ec>] (max9867_i2c_probe+0x1c/0xe0) [<c03f96ec>] (max9867_i2c_probe) from [<c038a708>] (i2c_device_probe+0x270/0x298) [<c038a708>] (i2c_device_probe) from [<c02fb37c>] (driver_probe_device+0x2b4/0x458) [<c02fb37c>] (driver_probe_device) from [<c02fb59c>] (__driver_attach+0x7c/0xec) [<c02fb59c>] (__driver_attach) from [<c02f9840>] (bus_for_each_dev+0x58/0x7c) [<c02f9840>] (bus_for_each_dev) from [<c02fa7cc>] (bus_add_driver+0x1a8/0x220) [<c02fa7cc>] (bus_add_driver) from [<c02fbe7c>] (driver_register+0xa0/0xe0) [<c02fbe7c>] (driver_register) from [<c038aa6c>] (i2c_register_driver+0x74/0xa0) [<c038aa6c>] (i2c_register_driver) from [<c0102570>] (do_one_initcall+0x134/0x15c) [<c0102570>] (do_one_initcall) from [<c0700da8>] (kernel_init_freeable+0x178/0x1b4) [<c0700da8>] (kernel_init_freeable) from [<c050122c>] (kernel_init+0x8/0x100) [<c050122c>] (kernel_init) from [<c01010e0>] (ret_from_fork+0x14/0x34) Exception stack(0xc381bfb0 to 0xc381bff8) bfa0: 00000000 00000000 00000000 00000000 bfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 bfe0: 00000000 00000000 00000000 00000000 00000013 00000000 ---[ end trace 3c79eadf2363e939 ]---
max9867: probe of 1-0018 failed with error -12
driver was instructed to alloc insane number of bytes using devm_kzalloc in max9867_i2c_probe.
Now, if probe function calls devm_kzalloc two times and one of them fails, you cannot easily say which one without looking at assembly listing.
Or did I misunderstand your question?
Best regards,
ladis
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Review static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 5 lines
(quoted diff) +0
-1@@ -258,7 +256,6 @@ static int usbtll_omap_probe(struct platform_device *pdev) GFP_KERNEL); if (!tll->ch_clk) { ret = -ENOMEM; - dev_err(dev, "Couldn't allocate memory for channel clocks\n");I'd either leave this one, just to know which allocation failed or better use something like this …
Quoted 3 lines
Quoted 1 line
Are you aware on the structure for a Linux allocation failure report?
Just created one (not OMAP and not this driver, but that does not matter now):
Thanks for your example.
Quoted 7 lines
---[ end trace 3c79eadf2363e939 ]---max9867: probe of 1-0018 failed with error -12
driver was instructed to alloc insane number of bytes using
devm_kzallocinmax9867_i2c_probe.
Now, if probe function callsdevm_kzalloctwo times and one of them fails, you cannot easily say which one without looking at assembly listing.
Will this situation change with any other implementation for such backtraces?
Quoted 1 line
Or did I misunderstand your question?
No. - It seems that we have found a “common wavelength”.
Would it become acceptable to move the mentioned memory allocation into an additional function implementation so that you could see a difference from the function call stack dump already?
Regards,
Markus
Re: [1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Quoted 18 lines · SF Markus Elfring
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Review static int usbtll_omap_probe(struct platform_device *pdev) · line 261
Quoted 5 lines
(quoted diff) +0
-1@@ -258,7 +256,6 @@ static int usbtll_omap_probe(struct platform_device *pdev) GFP_KERNEL); if (!tll->ch_clk) { ret = -ENOMEM; - dev_err(dev, "Couldn't allocate memory for channel clocks\n");I'd either leave this one, just to know which allocation failed or better use something like this …
Quoted 3 lines
Quoted 1 line
Are you aware on the structure for a Linux allocation failure report?
Just created one (not OMAP and not this driver, but that does not matter now):
Thanks for your example.
Quoted 3 lines
---[ end trace 3c79eadf2363e939 ]---max9867: probe of 1-0018 failed with error -12
Quoted 6 lines
Quoted 4 lines
driver was instructed to alloc insane number of bytes using
devm_kzallocinmax9867_i2c_probe.
Now, if probe function callsdevm_kzalloctwo times and one of them fails, you cannot easily say which one without looking at assembly listing.Will this situation change with any other implementation for such backtraces?
How much that situation changes depends mainly on that very person who is sending bugreport and his/her ability and willigness to eventually change said implementation. In the other words your question (presumably) expects a world of ideal backtraces, which is (so far) rarely the case.
Anyway, if we agree to change the way we allocate driver data here, the issue this debate is about will no longer exist.
Best reards,
ladis
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Now, if probe function calls
devm_kzalloctwo times and one of them fails, you cannot easily say which one without looking at assembly listing.Will this situation change with any other implementation for such backtraces?
How much that situation changes depends mainly on that very person who is sending bugreport and his/her ability and willigness to eventually change said implementation.
Have you got any more influence on the selection?
Which variant was applied for your example?
Quoted 2 lines
In the other words your question (presumably) expects a world of ideal backtraces, which is (so far) rarely the case.
I assume that further software evolution will matter.
Does an article like “The ORCs are coming” (by Jonathan Corbet from 2017-07-20) point information out which is also useful for this issue here?
https://lwn.net/Articles/728339/
Quoted 2 lines
Anyway, if we agree to change the way we allocate driver data here, the issue this debate is about will no longer exist.
Does your update suggestion contain still any additional error messages for memory allocation failures?
Regards,
Markus
Re: [1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Quoted 10 lines · SF Markus Elfring
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Now, if probe function calls
devm_kzalloctwo times and one of them fails, you cannot easily say which one without looking at assembly listing.Will this situation change with any other implementation for such backtraces?
How much that situation changes depends mainly on that very person who is sending bugreport and his/her ability and willigness to eventually change said implementation.
Have you got any more influence on the selection?
?
Quoted 1 line
Which variant was applied for your example?
ARM_UNWIND
Quoted 9 lines
Quoted 2 lines
In the other words your question (presumably) expects a world of ideal backtraces, which is (so far) rarely the case.
I assume that further software evolution will matter.
Does an article like “The ORCs are coming” (by Jonathan Corbet from 2017-07-20) point information out which is also useful for this issue here?
I'm aware of this article. Please bear in mind which driver you are modifying. Not everything is desktop or server machine with almost unlimited resources and embedded people are rarely using latest stuff with all that bells and whistles.
That said, you might end having only fragment of log in only one of thousands machines in field. And saying technician he needs to use another kernel (upgrade all machines) and wait another several weeks for bug to trigger is no way.
So until evolution reaches ARM land, my point stands unchanged: Make it single allocation or leave one of those two messages in place.
In practice it probably does not matter if we know which allocation failed. We simply run out of memmory.
Quoted 5 lines
Quoted 2 lines
Anyway, if we agree to change the way we allocate driver data here, the issue this debate is about will no longer exist.
Does your update suggestion contain still any additional error messages for memory allocation failures?
Of course not as there will be only one memory allocation in the probe function.
Best regards,
ladis
Re: [1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Quoted 3 lines
That said, you might end having only fragment of log in only one of thousands And saying technician he needs to use another kernel (upgrade all machines) and wait another several weeks for bug to trigger is no way.
This was not really my intention here.
Quoted 2 lines
So until evolution reaches ARM land, my point stands unchanged:
Make it single allocation
Did I indicate a similar design direction (for the preferred stack trace convenience) after your constructive feedback?
Quoted 1 line
or leave one of those two messages in place.
Are there any more preferences involved?
Quoted 2 lines
In practice it probably does not matter if we know which allocation failed. We simply run out of memmory.
Would anybody insist to know for which driver instance an allocation attempt was performed?
Quoted 4 lines
Quoted 2 lines
Does your update suggestion contain still any additional error messages for memory allocation failures?
Of course not as there will be only one memory allocation in the probe function.
Thanks for this clarification. - So I hope that your solution approach will be also fine. Will it supersede my proposal?
Regards,
Markus
Re: [1/3] mfd/omap-usb-tll: Delete two error messages for a failed memory allocation in usbtll_omap_probe()
Quoted 2 lines · SF Markus Elfring
Thanks for this clarification. - So I hope that your solution approach will be also fine. Will it supersede my proposal?
Who knows, perhaps it would be the best if you could judge yourself...
8<--------
Subject: [PATCH] mfd/omap-usb-tll: Allocate driver data at once
Allocating memory to store clk array together with driver data simplifies error unwinding and allows deleting memory allocation failure message as there is now only single point where allocation could fail.
--- drivers/mfd/omap-usb-tll.c | 57 +++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 33 deletions(-)
drivers/mfd/omap-usb-tll.c +24 -33
@@ -108,9 +108,9 @@ (x) != OMAP_EHCI_PORT_MODE_PHY)struct usbtll_omap { -int nch;/* num. of channels */ -struct clk **ch_clk; -void __iomem *base; +void __iomem *base; +int nch;/* num. of channels */ +struct clk *ch_clk[0 ];/* must be the last member */ };/*-------------------------------------------------------------------------*/
@@ -216,53 +216,50 @@ static int usbtll_omap_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct resource *res;struct usbtll_omap *tll; -int ret =0 ; -int i, ver; +void __iomem *base; +int i, nch, ver;dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); - tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); -if (!tll) { -dev_err (dev,"Memory allocation failed\n" ); -return -ENOMEM ; - } - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - tll->base =devm_ioremap_resource (dev, res); -if (IS_ERR (tll->base)) -return PTR_ERR (tll->base); + base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); -platform_set_drvdata (pdev, tll);pm_runtime_enable (dev);pm_runtime_get_sync (dev); - ver =usbtll_read (tll->base,OMAP_USBTLL_REVISION ); + ver =usbtll_read (base,OMAP_USBTLL_REVISION );switch (ver) {case OMAP_USBTLL_REV1 :case OMAP_USBTLL_REV4 : - tll->nch =OMAP_TLL_CHANNEL_COUNT ; + nch =OMAP_TLL_CHANNEL_COUNT ;break ;case OMAP_USBTLL_REV2 :case OMAP_USBTLL_REV3 : - tll->nch =OMAP_REV2_TLL_CHANNEL_COUNT ; + nch =OMAP_REV2_TLL_CHANNEL_COUNT ;break ;default : - tll->nch =OMAP_TLL_CHANNEL_COUNT ; + nch =OMAP_TLL_CHANNEL_COUNT ;dev_dbg (dev,"USB TLL Rev : 0x%x not recognized, assuming %d channels\n" , - ver, tll->nch); + ver, nch);break ; } - tll->ch_clk =devm_kzalloc (dev,sizeof (struct clk *) * tll->nch, -GFP_KERNEL ); -if (!tll->ch_clk) { - ret = -ENOMEM ; -dev_err (dev,"Couldn't allocate memory for channel clocks\n" ); - goto err_clk_alloc; + tll =devm_kzalloc (dev,sizeof (*tll) +sizeof (tll->ch_clk[nch]), +GFP_KERNEL ); +if (!tll) { +pm_runtime_put_sync (dev); +pm_runtime_disable (dev); +return -ENOMEM ; } -for (i =0 ; i < tll->nch; i++) { + tll->base = base; + tll->nch = nch; +platform_set_drvdata (pdev, tll); + +for (i =0 ; i < nch; i++) {char clkname[] ="usb_tll_hs_usb_chx_clk" ; snprintf(clkname, sizeof(clkname),
@@ -282,12 +279,6 @@ static int usbtll_omap_probe(struct platform_device *pdev)spin_unlock (&tll_lock);return 0 ; - -err_clk_alloc: -pm_runtime_put_sync (dev); -pm_runtime_disable (dev); - -return ret; }/**
Signature · 1 line
2.15.1
Re: mfd/omap-usb-tll: Allocate driver data at once in usbtll_omap_probe()
Quoted 4 lines
Quoted 2 lines
So I hope that your solution approach will be also fine. Will it supersede my proposal?
Who knows, perhaps it would be the best if you could judge yourself...
I am also curious on how other contributors will respond to your following update suggestion.
Quoted 3 lines
8<--------
Subject: [PATCH] mfd/omap-usb-tll: Allocate driver data at once
Would it have been clearer to use this information as the subject for this reply already?
Are you fine with that this change approach was recorded in a possibly questionable format?
https://patchwork.kernel.org/patch/10165193/
Quoted 4 lines
Allocating memory to store clk array together with driver data simplifies error unwinding and allows deleting memory allocation failure message as there is now only single point where allocation could fail.
* Will it matter to mention the previous software situation a bit in such a commit description?
* Would you like to add a tag “link”?
* Are you going to “supersede” any more source code adjustments around questionable error messages?
Regards,
Markus
Re: mfd/omap-usb-tll: Allocate driver data at once in usbtll_omap_probe()
Quoted 11 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines
So I hope that your solution approach will be also fine. Will it supersede my proposal?
Who knows, perhaps it would be the best if you could judge yourself...
I am also curious on how other contributors will respond to your following update suggestion.
Quoted 2 lines
8<--------
Quoted 8 lines
Quoted 1 line
Subject: [PATCH] mfd/omap-usb-tll: Allocate driver data at once
Would it have been clearer to use this information as the subject for this reply already?
Are you fine with that this change approach was recorded in a possibly questionable format?
https://patchwork.kernel.org/patch/10165193/
Sure. It does not seem anyone involved cares about patchwork.
Quoted 9 lines
Quoted 4 lines
Allocating memory to store clk array together with driver data simplifies error unwinding and allows deleting memory allocation failure message as there is now only single point where allocation could fail.
* Will it matter to mention the previous software situation a bit in such a commit description?
* Would you like to add a tag “link”?
Are you okay with this one?
https://lkml.org/lkml/2018/1/15/411
Quoted 2 lines
* Are you going to “supersede” any more source code adjustments around questionable error messages?
I'm going to handle it usual way:
- wait for feedback and modify accordingly
- collect tags
- resend as v2
Also, patch contains all your changes, so you should be credited somehow - hence the need for v2 anyway.
What about:
Feel free to propose anything else.
Best regards,
ladis
Re: mfd/omap-usb-tll: Allocate driver data at once in usbtll_omap_probe()
In reply to Ladislav Michldrivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 247
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +1
-1dev_dbg (dev,"USB TLL Rev : 0x%x not recognized, assuming %d channels\n" , - ver, tll->nch); + ver, nch);break ;
Does this format string need an other indentation when you touch this statement?
Regards,
Markus
Re: mfd/omap-usb-tll: Allocate driver data at once in usbtll_omap_probe()
Quoted 7 lines · SF Markus Elfring
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 247
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +1
-1dev_dbg (dev,"USB TLL Rev : 0x%x not recognized, assuming %d channels\n" , - ver, tll->nch); + ver, nch);break ;Does this format string need an other indentation when you touch this statement?
Well, lets that the chance and make it shorter as well:
default:
- tll->nch = OMAP_TLL_CHANNEL_COUNT;
- dev_dbg(dev,
- "USB TLL Rev : 0x%x not recognized, assuming %d channels\n",
- ver, tll->nch);
+ nch = OMAP_TLL_CHANNEL_COUNT;
+ dev_dbg(dev, "rev 0x%x not recognized, assuming %d channels\n",
+ ver, nch);
break;
Other proposals?
Re: mfd/omap-usb-tll: Allocate driver data at once in usbtll_omap_probe()
In reply to Ladislav MichlQuoted 4 lines
Quoted 1 line
* Would you like to add a tag “link”?
Are you okay with this one?
https://lkml.org/lkml/2018/1/15/411
Yes.
Quoted 1 line
- resend as v2
I was unsure about your patch handling from the previous replies.
Quoted 2 lines
Also, patch contains all your changes, so you should be credited somehow - hence the need for v2 anyway.
Thanks.
Quoted 2 lines
What about:
[marcus: simplified error unwinding, error message removal]
^
I would prefer my name written as in the other places.
Will this software development dialogue evolve in further constructive ways?
Regards,
Markus
Re: [PATCH 2/3] mfd/omap-usb-tll: Improve a size determination in usbtll_omap_probe()
In reply to SF Markus ElfringQuoted 19 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 15 Jan 2018 13:43:53 +0100Replace 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/mfd/omap-usb-tll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/mfd/omap-usb-tll.c +0
-0
drivers/mfd/omap-usb-tll.c static int usbtll_omap_probe(struct platform_device *pdev) · line 223
Quoted 4 lines
drivers/mfd/omap-usb-tll.c +0
-1@@ -220,8 +220,7 @@ static int usbtll_omap_probe(struct platform_device *pdev)int i, ver;dev_dbg (dev,"starting TI HSUSB TLL Controller\n" ); -
Keep the space between.
Quoted 5 lines
drivers/mfd/omap-usb-tll.c +1
-1- tll =devm_kzalloc (dev,sizeof (struct usbtll_omap ),GFP_KERNEL ); + tll =devm_kzalloc (dev,sizeof (*tll),GFP_KERNEL );if (!tll)return -ENOMEM ;
Signature · 8 lines
Lee Jones Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Lee Jones
AppliedRe: [PATCH 3/3] mfd/omap-usb-tll: Return an error code only as a constant in usbtll_omap_probe()
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 15 Jan 2018 14:00:45 +0100* Return an error code without storing it in an intermediate variable.
Quoted 7 lines
* Delete the label "
err_clk_alloc" and local variable "ret" which became unnecessary with this refactoring.Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/omap-usb-tll.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
Applied, thanks.
Signature · 8 lines
Lee Jones Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] mfd/omap-usb-tll: Return an error code only as a constant in usbtll_omap_probe()
Quoted 10 lines · Lee Jones
Quoted 8 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Mon, 15 Jan 2018 14:00:45 +0100* Return an error code without storing it in an intermediate variable.
* Delete the label "
err_clk_alloc" and local variable "ret" which became unnecessary with this refactoring.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/mfd/omap-usb-tll.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)Applied, thanks.
This patch does not apply.
Please rebase and resend.
Signature · 8 lines
Lee Jones Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [3/3] mfd/omap-usb-tll: Return an error code only as a constant in usbtll_omap_probe()
Quoted 5 lines
Quoted 1 line
Applied, thanks.
This patch does not apply.
Please rebase and resend.
Did you notice that this update suggestion could eventually be superseded by the software change “[PATCH v2] mfd: omap-usb-tll: Allocate driver data at once”?
https://lkml.org/lkml/2018/1/23/277
https://patchwork.kernel.org/patch/10165339/
https://lkml.kernel.org/r/<20180115202505.GA2628@lenoch>
Regards,
Markus
Re: [3/3] mfd/omap-usb-tll: Return an error code only as a constant in usbtll_omap_probe()
Quoted 8 lines · SF Markus Elfring
Quoted 5 lines
Quoted 1 line
Applied, thanks.
This patch does not apply.
Please rebase and resend.
Did you notice that this update suggestion could eventually be superseded by the software change “[PATCH v2] mfd: omap-usb-tll: Allocate driver data at once”?
How would I? It looks like a completely different patch.
In future, please either reply to the original patch with the follow-up patch OR reply to the original patch to say it's been superseded, and provide an indication of which patch superseded it.
Quoted 3 lines
https://lkml.org/lkml/2018/1/23/277
https://patchwork.kernel.org/patch/10165339/
https://lkml.kernel.org/r/<20180115202505.GA2628@lenoch>
Signature · 4 lines
Lee Jones Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [3/3] mfd/omap-usb-tll: Return an error code only as a constant in usbtll_omap_probe()
Lee,
Quoted 8 lines · Lee Jones
Quoted 6 lines · SF Markus Elfring
Quoted 5 lines
Quoted 1 line
Applied, thanks.
This patch does not apply.
Please rebase and resend.
Quoted 8 lines
Quoted 2 lines
Did you notice that this update suggestion could eventually be superseded by the software change “[PATCH v2] mfd: omap-usb-tll: Allocate driver data at once”?
How would I? It looks like a completely different patch.
In future, please either reply to the original patch with the follow-up patch OR reply to the original patch to say it's been superseded, and provide an indication of which patch superseded it.
this is my fault. I should point out that v2 superseded also other patches in the serie (see previous discussion, how that happened).
I'm sorry for this.
Quoted 9 lines
Quoted 3 lines
https://lkml.org/lkml/2018/1/23/277
https://patchwork.kernel.org/patch/10165339/
https://lkml.kernel.org/r/<20180115202505.GA2628@lenoch>Signature · 4 lines
Lee Jones Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Re: [3/3] mfd/omap-usb-tll: Return an error code only as a constant in usbtll_omap_probe()
Quoted 16 lines · Ladislav Michl
Lee,
Quoted 13 lines · Lee Jones
Quoted 8 lines · SF Markus Elfring
Quoted 5 lines
Quoted 1 line
Applied, thanks.
This patch does not apply.
Please rebase and resend.
Did you notice that this update suggestion could eventually be superseded by the software change “[PATCH v2] mfd: omap-usb-tll: Allocate driver data at once”?
How would I? It looks like a completely different patch.
Quoted 8 lines
Quoted 3 lines
In future, please either reply to the original patch with the follow-up patch OR reply to the original patch to say it's been superseded, and provide an indication of which patch superseded it.
this is my fault. I should point out that v2 superseded also other patches in the serie (see previous discussion, how that happened).
I'm sorry for this.
Not a problem.
Signature · 4 lines
Lee Jones Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog