From: SF Markus Elfring <hidden> Date: 2017-11-25 20:43:18
From: Markus Elfring <redacted>
Date: Sat, 25 Nov 2017 21:38:42 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Delete an error message for a failed memory allocation in two functions
Less checks in ufx_usb_probe() after error detection
Return an error code only as a constant in ufx_realloc_framebuffer()
Improve a size determination in two functions
Adjust three checks for null pointers
drivers/video/fbdev/smscufx.c | 80 ++++++++++++++++---------------------------
1 file changed, 29 insertions(+), 51 deletions(-)
--
2.15.0
From: SF Markus Elfring <hidden> Date: 2017-11-25 20:44:29
From: Markus Elfring <redacted>
Date: Sat, 25 Nov 2017 18:32:29 +0100
Omit an extra message for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <redacted>
---
drivers/video/fbdev/smscufx.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
@@ -1630,10 +1628,8 @@ static int ufx_usb_probe(struct usb_interface *interface,BUG_ON(!usbdev);dev=kzalloc(sizeof(*dev),GFP_KERNEL);-if(dev=NULL){-dev_err(&usbdev->dev,"ufx_usb_probe: failed alloc of dev struct\n");+if(!dev)gotoerror;-}/* we need to wait for both usb and fbdev to spin down on disconnect */kref_init(&dev->kref);/* matching kref_put in usb .disconnect fn */
From: SF Markus Elfring <hidden> Date: 2017-11-25 20:45:40
From: Markus Elfring <redacted>
Date: Sat, 25 Nov 2017 19:47:51 +0100
Up to four checks could be repeated by the ufx_usb_probe() function
during error handling even if the relevant properties can be determined
for the involved variables before by source code analysis.
* Return directly after a call of the function "kzalloc" failed
at the beginning.
* Adjust jump targets so that extra checks can be omitted at the end.
* Delete initialisations for the variables "info" and "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
drivers/video/fbdev/smscufx.c | 45 +++++++++++++++++--------------------------
1 file changed, 18 insertions(+), 27 deletions(-)
@@ -1619,8 +1619,8 @@ static int ufx_usb_probe(struct usb_interface *interface,{structusb_device*usbdev;structufx_data*dev;-structfb_info*info=NULL;-intretval=-ENOMEM;+structfb_info*info;+intretval;u32id_rev,fpga_rev;/* usb initialization */
@@ -1629,7 +1629,7 @@ static int ufx_usb_probe(struct usb_interface *interface,dev=kzalloc(sizeof(*dev),GFP_KERNEL);if(!dev)-gotoerror;+return-ENOMEM;/* we need to wait for both usb and fbdev to spin down on disconnect */kref_init(&dev->kref);/* matching kref_put in usb .disconnect fn */
@@ -1649,9 +1649,8 @@ static int ufx_usb_probe(struct usb_interface *interface,dev_dbg(dev->gdev,"fb_defio enable=%d\n",fb_defio);if(!ufx_alloc_urb_list(dev,WRITES_IN_FLIGHT,MAX_TRANSFER)){-retval=-ENOMEM;dev_err(dev->gdev,"ufx_alloc_urb_list failed\n");-gotoerror;+gotoe_nomem;}/* We don't register a new USB class. Our client interface is fbdev */
@@ -1659,9 +1658,8 @@ static int ufx_usb_probe(struct usb_interface *interface,/* allocates framebuffer driver structure, not framebuffer memory */info=framebuffer_alloc(0,&usbdev->dev);if(!info){-retval=-ENOMEM;dev_err(dev->gdev,"framebuffer_alloc failed\n");-gotoerror;+gotoe_nomem;}dev->info=info;
@@ -1733,26 +1731,19 @@ static int ufx_usb_probe(struct usb_interface *interface,return0;error:-if(dev){-if(info){-if(info->cmap.len!=0)-fb_dealloc_cmap(&info->cmap);-if(info->monspecs.modedb)-fb_destroy_modedb(info->monspecs.modedb);-vfree(info->screen_base);--fb_destroy_modelist(&info->modelist);--framebuffer_release(info);-}--kref_put(&dev->kref,ufx_free);/* ref for framebuffer */-kref_put(&dev->kref,ufx_free);/* last ref from kref_init */--/* dev has been deallocated. Do not dereference */-}-+destroy_modedb:+fb_destroy_modedb(info->monspecs.modedb);+vfree(info->screen_base);+fb_destroy_modelist(&info->modelist);+framebuffer_release(info);+put_ref:+kref_put(&dev->kref,ufx_free);/* ref for framebuffer */+kref_put(&dev->kref,ufx_free);/* last ref from kref_init */returnretval;++e_nomem:+retval=-ENOMEM;+gotoput_ref;}staticvoidufx_usb_disconnect(structusb_interface*interface)
From: SF Markus Elfring <hidden> Date: 2017-11-25 20:46:52
From: Markus Elfring <redacted>
Date: Sat, 25 Nov 2017 19:56:44 +0100
* Return an error code without storing it in an intermediate variable.
* Delete the label "error" and local variable "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
drivers/video/fbdev/smscufx.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-11-25 20:47:59
From: Markus Elfring <redacted>
Date: Sat, 25 Nov 2017 21:10:22 +0100
Replace the specification of data structures by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.
Signed-off-by: Markus Elfring <redacted>
---
drivers/video/fbdev/smscufx.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
From: SF Markus Elfring <hidden> Date: 2017-11-25 20:50:28
From: Markus Elfring <redacted>
Date: Sat, 25 Nov 2017 21:21:20 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script “checkpatch.pl” pointed information out like the following.
Comparison to NULL could be written …
Thus fix the affected source code places.
Signed-off-by: Markus Elfring <redacted>
---
drivers/video/fbdev/smscufx.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
@@ -1081,7 +1081,7 @@ static int ufx_ops_open(struct fb_info *info, int user)kref_get(&dev->kref);-if(fb_defio&&(info->fbdefio=NULL)){+if(fb_defio&&!info->fbdefio){/* enable defio at last moment if not disabled by client */structfb_deferred_io*fbdefio;
@@ -1556,8 +1556,7 @@ static int ufx_setup_modes(struct ufx_data *dev, struct fb_info *info,}/* If everything else has failed, fall back to safe default mode */-if(default_vmode=NULL){-+if(!default_vmode){structfb_videomodefb_vmode={0};/* Add the standard VESA modes to our modelist
@@ -1583,8 +1582,7 @@ static int ufx_setup_modes(struct ufx_data *dev, struct fb_info *info,}/* If we have good mode and no active clients */-if((default_vmode!=NULL)&&(dev->fb_count=0)){-+if(default_vmode&&dev->fb_count=0){fb_videomode_to_var(&info->var,default_vmode);ufx_var_color_format(&info->var);
From: SF Markus Elfring <hidden> Date: 2017-11-26 07:39:53
From: Markus Elfring <redacted>
Date: Sun, 26 Nov 2017 08:18:20 +0100
Up to four checks could be repeated by the ufx_usb_probe() function
during error handling even if the relevant properties can be determined
for the involved variables before by source code analysis.
* Return directly after a call of the function "kzalloc" failed
at the beginning.
* Adjust jump targets so that extra checks can be omitted at the end.
* Delete initialisations for the variables "info" and "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
v2:
A call of the function "fb_dealloc_cmap" was preserved for the exception
handling at the end.
drivers/video/fbdev/smscufx.c | 46 ++++++++++++++++++-------------------------
1 file changed, 19 insertions(+), 27 deletions(-)
@@ -1619,8 +1619,8 @@ static int ufx_usb_probe(struct usb_interface *interface,{structusb_device*usbdev;structufx_data*dev;-structfb_info*info=NULL;-intretval=-ENOMEM;+structfb_info*info;+intretval;u32id_rev,fpga_rev;/* usb initialization */
@@ -1629,7 +1629,7 @@ static int ufx_usb_probe(struct usb_interface *interface,dev=kzalloc(sizeof(*dev),GFP_KERNEL);if(!dev)-gotoerror;+return-ENOMEM;/* we need to wait for both usb and fbdev to spin down on disconnect */kref_init(&dev->kref);/* matching kref_put in usb .disconnect fn */
@@ -1649,9 +1649,8 @@ static int ufx_usb_probe(struct usb_interface *interface,dev_dbg(dev->gdev,"fb_defio enable=%d\n",fb_defio);if(!ufx_alloc_urb_list(dev,WRITES_IN_FLIGHT,MAX_TRANSFER)){-retval=-ENOMEM;dev_err(dev->gdev,"ufx_alloc_urb_list failed\n");-gotoerror;+gotoe_nomem;}/* We don't register a new USB class. Our client interface is fbdev */
@@ -1659,9 +1658,8 @@ static int ufx_usb_probe(struct usb_interface *interface,/* allocates framebuffer driver structure, not framebuffer memory */info=framebuffer_alloc(0,&usbdev->dev);if(!info){-retval=-ENOMEM;dev_err(dev->gdev,"framebuffer_alloc failed\n");-gotoerror;+gotoe_nomem;}dev->info=info;
@@ -1733,26 +1731,20 @@ static int ufx_usb_probe(struct usb_interface *interface,return0;error:-if(dev){-if(info){-if(info->cmap.len!=0)-fb_dealloc_cmap(&info->cmap);-if(info->monspecs.modedb)-fb_destroy_modedb(info->monspecs.modedb);-vfree(info->screen_base);--fb_destroy_modelist(&info->modelist);--framebuffer_release(info);-}--kref_put(&dev->kref,ufx_free);/* ref for framebuffer */-kref_put(&dev->kref,ufx_free);/* last ref from kref_init */--/* dev has been deallocated. Do not dereference */-}-+fb_dealloc_cmap(&info->cmap);+destroy_modedb:+fb_destroy_modedb(info->monspecs.modedb);+vfree(info->screen_base);+fb_destroy_modelist(&info->modelist);+framebuffer_release(info);+put_ref:+kref_put(&dev->kref,ufx_free);/* ref for framebuffer */+kref_put(&dev->kref,ufx_free);/* last ref from kref_init */returnretval;++e_nomem:+retval=-ENOMEM;+gotoput_ref;}staticvoidufx_usb_disconnect(structusb_interface*interface)
On Saturday, November 25, 2017 09:42:57 PM SF Markus Elfring wrote:
From: Markus Elfring <redacted>
Date: Sat, 25 Nov 2017 21:38:42 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Delete an error message for a failed memory allocation in two functions
This patch removes the information about the device for which the allocation
fails.
Less checks in ufx_usb_probe() after error detection
This patch depends on the earlier patch (which is not being merged) so please
re-base it if you want it to be applied.
Return an error code only as a constant in ufx_realloc_framebuffer()
ditto
Improve a size determination in two functions
Patch queued for 4.16, thanks.
Adjust three checks for null pointers
This patch contains unrelated change ({} braces addition) which should be
dropped.
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
From: SF Markus Elfring <hidden> Date: 2018-01-07 16:01:06
From: Markus Elfring <redacted>
Date: Sun, 7 Jan 2018 16:54:32 +0100
Three update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Less checks in ufx_usb_probe() after error detection
Return an error code only as a constant
in ufx_realloc_framebuffer()
Delete an error message for a failed memory allocation
in ufx_realloc_framebuffer()
---
v3:
Rebased on Linux next-20180105.
drivers/video/fbdev/smscufx.c | 59 ++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 37 deletions(-)
--
2.15.1
From: SF Markus Elfring <hidden> Date: 2018-01-07 16:02:34
From: Markus Elfring <redacted>
Date: Sun, 7 Jan 2018 15:56:11 +0100
Up to four checks could be repeated by the ufx_usb_probe() function
during error handling even if the relevant properties can be determined
for the involved variables before by source code analysis.
* Return directly after a call of the function "kzalloc" failed
at the beginning.
* Adjust jump targets so that extra checks can be omitted at the end.
* Delete initialisations for the variables "info" and "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
v3:
This update suggestion was rebased on source files from the software
"Linux next-20180105".
v2:
A call of the function "fb_dealloc_cmap" was preserved for the exception
handling at the end.
drivers/video/fbdev/smscufx.c | 46 ++++++++++++++++++-------------------------
1 file changed, 19 insertions(+), 27 deletions(-)
@@ -1620,8 +1620,8 @@ static int ufx_usb_probe(struct usb_interface *interface,{structusb_device*usbdev;structufx_data*dev;-structfb_info*info=NULL;-intretval=-ENOMEM;+structfb_info*info;+intretval;u32id_rev,fpga_rev;/* usb initialization */
@@ -1631,7 +1631,7 @@ static int ufx_usb_probe(struct usb_interface *interface,dev=kzalloc(sizeof(*dev),GFP_KERNEL);if(dev=NULL){dev_err(&usbdev->dev,"ufx_usb_probe: failed alloc of dev struct\n");-gotoerror;+return-ENOMEM;}/* we need to wait for both usb and fbdev to spin down on disconnect */
@@ -1652,9 +1652,8 @@ static int ufx_usb_probe(struct usb_interface *interface,dev_dbg(dev->gdev,"fb_defio enable=%d\n",fb_defio);if(!ufx_alloc_urb_list(dev,WRITES_IN_FLIGHT,MAX_TRANSFER)){-retval=-ENOMEM;dev_err(dev->gdev,"ufx_alloc_urb_list failed\n");-gotoerror;+gotoe_nomem;}/* We don't register a new USB class. Our client interface is fbdev */
@@ -1662,9 +1661,8 @@ static int ufx_usb_probe(struct usb_interface *interface,/* allocates framebuffer driver structure, not framebuffer memory */info=framebuffer_alloc(0,&usbdev->dev);if(!info){-retval=-ENOMEM;dev_err(dev->gdev,"framebuffer_alloc failed\n");-gotoerror;+gotoe_nomem;}dev->info=info;
@@ -1736,26 +1734,20 @@ static int ufx_usb_probe(struct usb_interface *interface,return0;error:-if(dev){-if(info){-if(info->cmap.len!=0)-fb_dealloc_cmap(&info->cmap);-if(info->monspecs.modedb)-fb_destroy_modedb(info->monspecs.modedb);-vfree(info->screen_base);--fb_destroy_modelist(&info->modelist);--framebuffer_release(info);-}--kref_put(&dev->kref,ufx_free);/* ref for framebuffer */-kref_put(&dev->kref,ufx_free);/* last ref from kref_init */--/* dev has been deallocated. Do not dereference */-}-+fb_dealloc_cmap(&info->cmap);+destroy_modedb:+fb_destroy_modedb(info->monspecs.modedb);+vfree(info->screen_base);+fb_destroy_modelist(&info->modelist);+framebuffer_release(info);+put_ref:+kref_put(&dev->kref,ufx_free);/* ref for framebuffer */+kref_put(&dev->kref,ufx_free);/* last ref from kref_init */returnretval;++e_nomem:+retval=-ENOMEM;+gotoput_ref;}staticvoidufx_usb_disconnect(structusb_interface*interface)
From: SF Markus Elfring <hidden> Date: 2018-01-07 16:05:58
From: Markus Elfring <redacted>
Date: Sun, 7 Jan 2018 16:07:11 +0100
* Return an error code without storing it in an intermediate variable.
* Delete the label "error" and local variable "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
v3:
This update suggestion was rebased on source files from the software
"Linux next-20180105".
drivers/video/fbdev/smscufx.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
From: SF Markus Elfring <hidden> Date: 2018-01-07 16:06:30
From: Markus Elfring <redacted>
Date: Sun, 7 Jan 2018 16:12:40 +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 <redacted>
---
v3:
This update suggestion was rebased on source files from the software
"Linux next-20180105".
drivers/video/fbdev/smscufx.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
On Sunday, January 07, 2018 05:02:21 PM SF Markus Elfring wrote:
From: Markus Elfring <redacted>
Date: Sun, 7 Jan 2018 15:56:11 +0100
Up to four checks could be repeated by the ufx_usb_probe() function
during error handling even if the relevant properties can be determined
for the involved variables before by source code analysis.
* Return directly after a call of the function "kzalloc" failed
at the beginning.
* Adjust jump targets so that extra checks can be omitted at the end.
* Delete initialisations for the variables "info" and "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
Patch queued for 4.17, thanks.
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
On Sunday, January 07, 2018 05:04:04 PM SF Markus Elfring wrote:
From: Markus Elfring <redacted>
Date: Sun, 7 Jan 2018 16:07:11 +0100
* Return an error code without storing it in an intermediate variable.
* Delete the label "error" and local variable "retval"
which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
Patch queued for 4.17, thanks.
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
On Sunday, January 07, 2018 05:06:13 PM SF Markus Elfring wrote:
From: Markus Elfring <redacted>
Date: Sun, 7 Jan 2018 16:12:40 +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 <redacted>
Patch queued for 4.17, thanks.
Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics