* [PATCH 0/3] char-pcmcia: Adjustments for ten function implementations
@ 2017-10-16 12:17 SF Markus Elfring
2017-10-16 12:18 ` [PATCH 1/3] char/pcmcia: Delete an error message for a failed memory allocation in mgslpc_probe() SF Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-10-16 12:17 UTC (permalink / raw)
To: David S. Miller, Jarod Wilson, Johannes Berg, Stephen Hemminger,
kernel-janitors
Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
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(-)
--
2.14.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] char/pcmcia: Delete an error message for a failed memory allocation in mgslpc_probe()
2017-10-16 12:17 [PATCH 0/3] char-pcmcia: Adjustments for ten function implementations SF Markus Elfring
@ 2017-10-16 12:18 ` SF Markus Elfring
2017-10-16 12:19 ` [PATCH 2/3] char/pcmcia: Improve nine size determinations SF Markus Elfring
2017-10-16 12:20 ` [PATCH 3/3] char/pcmcia: Adjust a null pointer check in three functions SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-10-16 12:18 UTC (permalink / raw)
To: David S. Miller, Jarod Wilson, Johannes Berg, Stephen Hemminger,
kernel-janitors
Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/pcmcia/synclink_cs.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 62be953e5fb0..4db7eda2e7f2 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -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);
--
2.14.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] char/pcmcia: Improve nine size determinations
2017-10-16 12:17 [PATCH 0/3] char-pcmcia: Adjustments for ten function implementations SF Markus Elfring
2017-10-16 12:18 ` [PATCH 1/3] char/pcmcia: Delete an error message for a failed memory allocation in mgslpc_probe() SF Markus Elfring
@ 2017-10-16 12:19 ` SF Markus Elfring
2017-10-16 12:20 ` [PATCH 3/3] char/pcmcia: Adjust a null pointer check in three functions SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-10-16 12:19 UTC (permalink / raw)
To: David S. Miller, Jarod Wilson, Johannes Berg, Stephen Hemminger,
kernel-janitors
Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/pcmcia/synclink_cs.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 4db7eda2e7f2..6c210b5cdf69 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -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, struct
if (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;
--
2.14.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] char/pcmcia: Adjust a null pointer check in three functions
2017-10-16 12:17 [PATCH 0/3] char-pcmcia: Adjustments for ten function implementations SF Markus Elfring
2017-10-16 12:18 ` [PATCH 1/3] char/pcmcia: Delete an error message for a failed memory allocation in mgslpc_probe() SF Markus Elfring
2017-10-16 12:19 ` [PATCH 2/3] char/pcmcia: Improve nine size determinations SF Markus Elfring
@ 2017-10-16 12:20 ` SF Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: SF Markus Elfring @ 2017-10-16 12:20 UTC (permalink / raw)
To: David S. Miller, Jarod Wilson, Johannes Berg, Stephen Hemminger,
kernel-janitors
Cc: LKML
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/char/pcmcia/synclink_cs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 6c210b5cdf69..1719d929c0e4 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -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;
}
--
2.14.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-16 12:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-16 12:17 [PATCH 0/3] char-pcmcia: Adjustments for ten function implementations SF Markus Elfring
2017-10-16 12:18 ` [PATCH 1/3] char/pcmcia: Delete an error message for a failed memory allocation in mgslpc_probe() SF Markus Elfring
2017-10-16 12:19 ` [PATCH 2/3] char/pcmcia: Improve nine size determinations SF Markus Elfring
2017-10-16 12:20 ` [PATCH 3/3] char/pcmcia: Adjust a null pointer check in three functions SF Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox