usbip: Adjustments for two function implementations
Subsystems (3)
cover usbip: Adjustments for two function implementations
From: Markus Elfring <[email protected]>
Date: Tue, 5 Dec 2017 22:44:55 +0100
Two update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Delete an error message for a failed memory allocation in two functions Use common error handling code in stub_recv_cmd_submit()
drivers/usb/usbip/stub_rx.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
Signature · 1 line
2.15.1
PATCH 1/2 usbip: Delete an error message for a failed memory allocation in two functions
From: Markus Elfring <[email protected]>
Date: Tue, 5 Dec 2017 22:25:38 +0100
Omit an extra message for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
--- drivers/usb/usbip/stub_rx.c | 2 -- 1 file changed, 2 deletions(-)
drivers/usb/usbip/stub_rx.c +0 -2
@@ -302,7 +302,6 @@ static struct stub_priv *stub_priv_alloc(struct stub_device *sdev, priv =kmem_cache_zalloc (stub_priv_cache,GFP_ATOMIC );if (!priv) { -dev_err (&sdev->udev->dev,"alloc stub_priv\n" );spin_unlock_irqrestore (&sdev->priv_lock, flags);usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC );return NULL ;
@@ -466,7 +465,6 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, priv->urb->setup_packet =kmemdup (&pdu->u.cmd_submit.setup,8 ,GFP_KERNEL );if (!priv->urb->setup_packet) { -dev_err (&udev->dev,"allocate setup_packet\n" );usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC );return ; }
Signature · 1 line
2.15.1
PATCH 2/2 usbip: Use common error handling code in stub_recv_cmd_submit()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 5 Dec 2017 22:40:30 +0100
Add a jump target so that a bit of exception handling can be better reused at the end of this function.
--- drivers/usb/usbip/stub_rx.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/usb/usbip/stub_rx.c +10 -12
@@ -445,29 +445,23 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,else priv->urb =usb_alloc_urb (0 ,GFP_KERNEL ); -if (!priv->urb) { -usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC ); -return ; - } +if (!priv->urb) + goto add_event_malloc_failure;/* allocate urb transfer buffer, if needed */ if (pdu->u.cmd_submit.transfer_buffer_length >0 ) { priv->urb->transfer_buffer kzalloc(pdu->u.cmd_submit.transfer_buffer_length,GFP_KERNEL ); -if (!priv->urb->transfer_buffer) { -usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC ); -return ; - } +if (!priv->urb->transfer_buffer) + goto add_event_malloc_failure; }/* copy urb setup packet */ priv->urb->setup_packet =kmemdup (&pdu->u.cmd_submit.setup,8 ,GFP_KERNEL ); -if (!priv->urb->setup_packet) { -usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC ); -return ; - } +if (!priv->urb->setup_packet) + goto add_event_malloc_failure;/* set other members from the base header of pdu */ priv->urb->context = (void *) priv;
@@ -507,6 +501,10 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, }usbip_dbg_stub_rx ("Leave\n" ); +return ; + +add_event_malloc_failure: +usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC ); }/* recv a pdu */
Signature · 1 line
2.15.1
Shuah Khan
maintainerRe: [PATCH 1/2] usbip: Delete an error message for a failed memory allocation in two functions
In reply to SF Markus ElfringQuoted 6 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 5 Dec 2017 22:25:38 +0100Omit an extra message for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
Please include the problem and log from Coccinelle software in any future patches for the issues detected by Coccinelle.
Quoted 19 lines
Signed-off-by Markus Elfring <[email protected]>--- drivers/usb/usbip/stub_rx.c | 2 -- 1 file changed, 2 deletions(-)drivers/usb/usbip/stub_rx.c +0
-1@@ -302,7 +302,6 @@ static struct stub_priv *stub_priv_alloc(struct stub_device *sdev, priv =kmem_cache_zalloc (stub_priv_cache,GFP_ATOMIC );if (!priv) { -dev_err (&sdev->udev->dev,"alloc stub_priv\n" );spin_unlock_irqrestore (&sdev->priv_lock, flags);usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC );return NULL ;
drivers/usb/usbip/stub_rx.c static void stub_recv_cmd_submit(struct stub_device *sdev, · line 469
Quoted 4 lines
drivers/usb/usbip/stub_rx.c +0
-1@@ -466,7 +465,6 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, priv->urb->setup_packet =kmemdup (&pdu->u.cmd_submit.setup,8 ,GFP_KERNEL );if (!priv->urb->setup_packet) { -dev_err (&udev->dev,"allocate setup_packet\n" );
If Coccinelle found this as an extra message, there is something wrong with the Coccinelle script. This is not an extra message. This message is for the second kmemdup() failure and is necessary.
drivers/usb/usbip/stub_rx.c static void stub_recv_cmd_submit(struct stub_device *sdev, · line 470
Quoted 4 lines
drivers/usb/usbip/stub_rx.c +0
-0usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC );return ; }
thanks,
-- Shuah
Shuah Khan
maintainerRe: [PATCH 2/2] usbip: Use common error handling code in stub_recv_cmd_submit()
In reply to SF Markus ElfringQuoted 33 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 5 Dec 2017 22:40:30 +0100Add 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/usb/usbip/stub_rx.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)drivers/usb/usbip/stub_rx.c +2
-7@@ -445,29 +445,23 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,else priv->urb =usb_alloc_urb (0 ,GFP_KERNEL ); -if (!priv->urb) { -usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC ); -return ; - } +if (!priv->urb) + goto add_event_malloc_failure;/* allocate urb transfer buffer, if needed */ if (pdu->u.cmd_submit.transfer_buffer_length >0 ) { priv->urb->transfer_buffer >kzalloc (pdu->u.cmd_submit.transfer_buffer_length,GFP_KERNEL ); -if (!priv->urb->transfer_buffer) { -usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC ); -return ;
drivers/usb/usbip/stub_rx.c static void stub_recv_cmd_submit(struct stub_device *sdev, · line 467
Quoted 10 lines
drivers/usb/usbip/stub_rx.c +2
-3- } +if (!priv->urb->transfer_buffer) + goto add_event_malloc_failure; }/* copy urb setup packet */ priv->urb->setup_packet =kmemdup (&pdu->u.cmd_submit.setup,8 ,GFP_KERNEL ); -if (!priv->urb->setup_packet) { -usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC );
Please see comments on my comments on the previous patch in this series. This patch depends on the patch that is incorrect.
Quoted 9 lines
drivers/usb/usbip/stub_rx.c +2
-2-return ; - } +if (!priv->urb->setup_packet) + goto add_event_malloc_failure;/* set other members from the base header of pdu */ priv->urb->context = (void *) priv;
drivers/usb/usbip/stub_rx.c static void stub_recv_cmd_submit(struct stub_device *sdev, · line 510
Quoted 10 lines
drivers/usb/usbip/stub_rx.c +4
-0@@ -507,6 +501,10 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, }usbip_dbg_stub_rx ("Leave\n" ); +return ; + +add_event_malloc_failure: +usbip_event_add (ud,SDEV_EVENT_ERROR_MALLOC ); }/* recv a pdu */
I am restructuring this routine to fix a bug and so it stands now, I don't see a value in taking this patch that doesn't really fix any specific bug.
thanks,
-- Shuah
Re: [PATCH 1/2] usbip: Delete an error message for a failed memory allocation in two functions
In reply to Shuah KhanQuoted 5 lines
Quoted 3 lines
Omit an extra message for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
Please include the problem
Do you find the wording “WARNING: Possible unnecessary 'out of memory' message” from the script “checkpatch.pl” more reasonable?
Quoted 1 line
and log from Coccinelle software
There is no log file from which I could extract something for this case.
Quoted 1 line
in any future patches for the issues detected by Coccinelle.
Would you like to help a bit to make the commit message better for your needs?
Quoted 8 lines
drivers/usb/usbip/stub_rx.c static void stub_recv_cmd_submit(struct stub_device *sdev, · line 469
Quoted 5 lines
drivers/usb/usbip/stub_rx.c +0
-1@@ -466,7 +465,6 @@ static void stub_recv_cmd_submit(struct stub_device *sdev, priv->urb->setup_packet =kmemdup (&pdu->u.cmd_submit.setup,8 ,GFP_KERNEL );if (!priv->urb->setup_packet) { -dev_err (&udev->dev,"allocate setup_packet\n" );If Coccinelle found this as an extra message, there is something wrong with the Coccinelle script.
The source code analysis approach could be improved somehow.
Quoted 1 line
This is not an extra message.
There can be different opinions around the handling of such exceptional situations.
Quoted 1 line
This message is for the second
kmemdup()failure and is necessary.
This function is called only once within the implementation of the function “stub_recv_cmd_submit” (and in this source file).
Do you find a default Linux allocation failure report insufficient?
Regards,
Markus