char-pcmcia: Adjustments for ten function implementations
Subsystems (2)
cover char-pcmcia: Adjustments for ten function implementations
From: Markus Elfring <[email protected]>
Date: Mon, 16 Oct 2017 14:10:34 +0200
Three update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Delete an error message for a failed memory allocation in mgslpc_probe() Improve nine size determinations
Adjust a null pointer check in three functions
drivers/char/pcmcia/synclink_cs.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
Signature · 1 line
2.14.2
PATCH 1/3 char/pcmcia: Delete an error message for a failed memory allocation in mgslpc_probe()
From: Markus Elfring <[email protected]>
Date: Mon, 16 Oct 2017 11:46:38 +0200
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- drivers/char/pcmcia/synclink_cs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/char/pcmcia/synclink_cs.c +1 -3
@@ -520,10 +520,8 @@ static int mgslpc_probe(struct pcmcia_device *link)printk ("mgslpc_attach\n" ); info =kzalloc (sizeof (MGSLPC_INFO ),GFP_KERNEL ); -if (!info) { -printk ("Error can't allocate device instance data\n" ); +if (!info)return -ENOMEM ; - } info->magic =MGSLPC_MAGIC ;tty_port_init (&info->port);
Signature · 1 line
2.14.2
PATCH 2/3 char/pcmcia: Improve nine size determinations
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 16 Oct 2017 13:33:04 +0200
Replace the specification of data types by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/char/pcmcia/synclink_cs.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/char/pcmcia/synclink_cs.c +10 -9
@@ -519,7 +519,7 @@ static int mgslpc_probe(struct pcmcia_device *link)if (debug_level >=DEBUG_LEVEL_INFO )printk ("mgslpc_attach\n" ); - info =kzalloc (sizeof (MGSLPC_INFO ),GFP_KERNEL ); + info =kzalloc (sizeof (*info),GFP_KERNEL );if (!info)return -ENOMEM ;
@@ -534,7 +534,7 @@ static int mgslpc_probe(struct pcmcia_device *link)init_waitqueue_head (&info->event_wait_q);spin_lock_init (&info->lock);spin_lock_init (&info->netlock); -memcpy (&info->params,&default_params,sizeof (MGSL_PARAMS )); +memcpy (&info->params, &default_params,sizeof (default_params)); info->idle_mode =HDLC_TXIDLE_FLAGS ; info->imra_value =0xffff ; info->imrb_value =0xffff ;
@@ -1771,7 +1771,8 @@ static int get_stats(MGSLPC_INFO * info, struct mgsl_icount __user *user_icount)if (!user_icount) {memset (&info->icount,0 ,sizeof (info->icount)); }else { -COPY_TO_USER (err, user_icount, &info->icount,sizeof (struct mgsl_icount )); +COPY_TO_USER (err, user_icount, &info->icount, +sizeof (*user_icount));if (err)return -EFAULT ; }
@@ -1785,7 +1786,7 @@ static int get_params(MGSLPC_INFO * info, MGSL_PARAMS __user *user_params)int err;if (debug_level >=DEBUG_LEVEL_INFO )printk ("get_params(%s)\n" , info->device_name); -COPY_TO_USER (err,user_params, &info->params,sizeof (MGSL_PARAMS )); +COPY_TO_USER (err, user_params, &info->params,sizeof (*user_params));if (err)return -EFAULT ;return 0 ;
@@ -1809,7 +1810,7 @@ static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params, structif (debug_level >=DEBUG_LEVEL_INFO )printk ("%s(%d):set_params %s\n" , __FILE__,__LINE__, info->device_name); -COPY_FROM_USER (err,&tmp_params, new_params,sizeof (MGSL_PARAMS )); +COPY_FROM_USER (err, &tmp_params, new_params,sizeof (tmp_params));if (err) {if (debug_level >=DEBUG_LEVEL_INFO ) printk("%s(%d):set_params(%s) user buffer copy failed\n",
@@ -1818,7 +1819,7 @@ static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params, struct }spin_lock_irqsave (&info->lock, flags); -memcpy (&info->params,&tmp_params,sizeof (MGSL_PARAMS )); +memcpy (&info->params, &tmp_params,sizeof (tmp_params));spin_unlock_irqrestore (&info->lock, flags);mgslpc_change_params (info, tty);
@@ -1831,7 +1832,7 @@ static int get_txidle(MGSLPC_INFO * info, int __user *idle_mode)int err;if (debug_level >=DEBUG_LEVEL_INFO )printk ("get_txidle(%s)=%d\n" , info->device_name, info->idle_mode); -COPY_TO_USER (err,idle_mode, &info->idle_mode,sizeof (int )); +COPY_TO_USER (err, idle_mode, &info->idle_mode,sizeof (*idle_mode));if (err)return -EFAULT ;return 0 ;
@@ -1854,7 +1855,7 @@ static int get_interface(MGSLPC_INFO * info, int __user *if_mode)int err;if (debug_level >=DEBUG_LEVEL_INFO )printk ("get_interface(%s)=%d\n" , info->device_name, info->if_mode); -COPY_TO_USER (err,if_mode, &info->if_mode,sizeof (int )); +COPY_TO_USER (err, if_mode, &info->if_mode,sizeof (*if_mode));if (err)return -EFAULT ;return 0 ;
@@ -1959,7 +1960,7 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr)struct _input_signal_events oldsigs, newsigs;DECLARE_WAITQUEUE (wait, current); -COPY_FROM_USER (rc,&mask, mask_ptr,sizeof (int )); +COPY_FROM_USER (rc, &mask, mask_ptr,sizeof (mask));if (rc)return -EFAULT ;
Signature · 1 line
2.14.2
PATCH 3/3 char/pcmcia: Adjust a null pointer check in three functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 16 Oct 2017 13:46:00 +0200
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.
--- drivers/char/pcmcia/synclink_cs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/char/pcmcia/synclink_cs.c +3 -3
@@ -2644,7 +2644,7 @@ static int rx_alloc_buffers(MGSLPC_INFO *info) info->rx_buf_count = info->rx_buf_total_size / info->rx_buf_size; info->rx_buf =kmalloc (info->rx_buf_total_size,GFP_KERNEL ); -if (info->rx_buf =NULL ) +if (!info->rx_buf)return -ENOMEM ;/* unused flag buffer to satisfy receive_buf calling interface */
@@ -4228,7 +4228,7 @@ static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size)if (debug_level >=DEBUG_LEVEL_INFO )printk ("hdlcdev_rx(%s)\n" , dev->name); -if (skb =NULL ) { +if (!skb) {printk (KERN_NOTICE "%s: can't alloc skb, dropping packet\n" , dev->name); dev->stats.rx_dropped++;return ;
@@ -4269,7 +4269,7 @@ static int hdlcdev_init(MGSLPC_INFO *info)/* allocate and initialize network and HDLC layer objects */ dev =alloc_hdlcdev (info); -if (dev =NULL ) { +if (!dev) {printk (KERN_ERR "%s:hdlc device allocation failure\n" , __FILE__);return -ENOMEM ; }
Signature · 1 line
2.14.2