diff mbox

[OPW,kernel] staging:usbip: Add check for sscanf return value.

Message ID 20140308105324.GA17861@himangi-Inspiron-N5110gmail.com
State New, archived
Headers show

Commit Message

HIMANGI SARAOGI March 8, 2014, 10:53 a.m. UTC
This patch fixes the checkpatch.pl warning -
WARNING: unchecked sscanf return value
by adding a check for the returned value.

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
---
 drivers/staging/usbip/stub_dev.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Sarah Sharp March 9, 2014, 3:44 a.m. UTC | #1
On Sat, Mar 08, 2014 at 04:23:24PM +0530, Himangi Saraogi wrote:
> This patch fixes the checkpatch.pl warning -
> WARNING: unchecked sscanf return value
> by adding a check for the returned value.

Looks like Elena beat you to this change:

4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  83) static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  84)                            const char *buf, size_t count)
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  85) {
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  86)        struct stub_device *sdev = dev_get_drvdata(dev);
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  87)        int sockfd = 0;
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  88)        struct socket *socket;
31398f6307d52 (Kurt Kanzenbach    2013-04-04 16:03:08 +0200  89)        ssize_t err = -EINVAL;
f8cfc02309090 (Elena Oat          2014-02-27 12:26:52 +0200  90)        int rv;
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  91) 
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  92)        if (!sdev) {
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  93)                dev_err(dev, "sdev is null\n");
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  94)                return -ENODEV;
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  95)        }
4d7b5c7f8ad49 (Takahiro Hirofuchi 2008-07-09 14:56:51 -0600  96) 
f8cfc02309090 (Elena Oat          2014-02-27 12:26:52 +0200  97)        rv = sscanf(buf, "%d", &sockfd);
f8cfc02309090 (Elena Oat          2014-02-27 12:26:52 +0200  98)        if (rv != 1)
f8cfc02309090 (Elena Oat          2014-02-27 12:26:52 +0200  99)                return -EINVAL;

Please rebase your patches against staging-next.

Sarah Sharp

> 
> Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
> ---
>  drivers/staging/usbip/stub_dev.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
> index b0bfd34..946f4cd 100644
> --- a/drivers/staging/usbip/stub_dev.c
> +++ b/drivers/staging/usbip/stub_dev.c
> @@ -93,7 +93,8 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
>  		return -ENODEV;
>  	}
>  
> -	sscanf(buf, "%d", &sockfd);
> +	if (sscanf(buf, "%d", &sockfd) != 1)
> +		return -EINVAL;
>  
>  	if (sockfd != -1) {
>  		dev_info(dev, "stub up\n");
> -- 
> 1.7.9.5
> 
> -- 
> You received this message because you are subscribed to the Google Groups "opw-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to opw-kernel+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
diff mbox

Patch

diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index b0bfd34..946f4cd 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -93,7 +93,8 @@  static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
 		return -ENODEV;
 	}
 
-	sscanf(buf, "%d", &sockfd);
+	if (sscanf(buf, "%d", &sockfd) != 1)
+		return -EINVAL;
 
 	if (sockfd != -1) {
 		dev_info(dev, "stub up\n");