From elfring at users.sourceforge.net Mon May 15 05:25:13 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 14:25:13 +0200 Subject: [PATCH 0/4] PCMCIA-PD6729: Adjustments for four function implementations Message-ID: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> From: Markus Elfring Date: Mon, 15 May 2017 14:05:06 +0200 A few update suggestions were taken into account from static source code analysis. Markus Elfring (4): Use kcalloc() in pd6729_pci_probe() Delete an error message for a failed memory allocation in pd6729_pci_probe() Add the macro "pr_fmt" Combine substrings for six messages drivers/pcmcia/pd6729.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) -- 2.13.0 From elfring at users.sourceforge.net Mon May 15 05:26:39 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 14:26:39 +0200 Subject: [PATCH 1/4] pcmcia: pd6729: Use kcalloc() in pd6729_pci_probe() In-Reply-To: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> References: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> Message-ID: From: Markus Elfring Date: Mon, 15 May 2017 11:41:00 +0200 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kcalloc". This issue was detected by using the Coccinelle software. * Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- drivers/pcmcia/pd6729.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index 0f70b4d58f9e..289a5e74e852 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -628,6 +628,5 @@ static int pd6729_pci_probe(struct pci_dev *dev, char configbyte; struct pd6729_socket *socket; - socket = kzalloc(sizeof(struct pd6729_socket) * MAX_SOCKETS, - GFP_KERNEL); + socket = kcalloc(MAX_SOCKETS, sizeof(*socket), GFP_KERNEL); if (!socket) { -- 2.13.0 From elfring at users.sourceforge.net Mon May 15 05:27:58 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 14:27:58 +0200 Subject: [PATCH 2/4] pcmcia: pd6729: Delete an error message for a failed memory allocation in pd6729_pci_probe() In-Reply-To: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> References: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> Message-ID: <6f241ada-c3a4-2dc1-206a-ead47de4214e@users.sourceforge.net> From: Markus Elfring Date: Mon, 15 May 2017 12:44:23 +0200 Omit an extra message for a memory allocation failure in this function. This issue was detected by using the Coccinelle software. Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf Signed-off-by: Markus Elfring --- drivers/pcmcia/pd6729.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index 289a5e74e852..a723ffbbd691 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -632,7 +632,5 @@ static int pd6729_pci_probe(struct pci_dev *dev, - if (!socket) { - dev_warn(&dev->dev, "failed to kzalloc socket.\n"); + if (!socket) return -ENOMEM; - } ret = pci_enable_device(dev); if (ret) { -- 2.13.0 From elfring at users.sourceforge.net Mon May 15 05:29:01 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 14:29:01 +0200 Subject: [PATCH 3/4] pcmcia: pd6729: Add the macro "pr_fmt" In-Reply-To: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> References: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> Message-ID: <6afb72fc-18c4-3fbd-17c6-54fb535f495c@users.sourceforge.net> From: Markus Elfring Date: Mon, 15 May 2017 13:15:33 +0200 Add a definition for the macro "pr_fmt" so that its information can be used for consistent message output. Signed-off-by: Markus Elfring --- drivers/pcmcia/pd6729.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index a723ffbbd691..b3422119820a 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -7,6 +7,8 @@ * the GNU General Public License, incorporated herein by reference. */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include -- 2.13.0 From elfring at users.sourceforge.net Mon May 15 05:30:08 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 14:30:08 +0200 Subject: [PATCH 4/4] pcmcia: pd6729: Combine substrings for six messages In-Reply-To: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> References: <07cd817c-3045-72d8-34e2-e81b73efc291@users.sourceforge.net> Message-ID: From: Markus Elfring Date: Mon, 15 May 2017 13:50:52 +0200 The script "checkpatch.pl" pointed information out like the following. WARNING: quoted string split across lines Thus fix the affected source code places. Prefer usage of the macros "pr_err" and "pr_info" over the interface "printk". Signed-off-by: Markus Elfring --- drivers/pcmcia/pd6729.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index b3422119820a..841f413c0d03 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -183,8 +183,7 @@ static irqreturn_t pd6729_interrupt(int irq, void *dev) while (1) { loopcount++; if (loopcount > 20) { - printk(KERN_ERR "pd6729: infinite eventloop " - "in interrupt\n"); + pr_err("infinite event loop in interrupt\n"); break; } @@ -348,8 +347,8 @@ static int pd6729_set_socket(struct pcmcia_socket *sock, socket_state_t *state) break; default: dev_dbg(&sock->dev, - "pd6729_set_socket called with invalid VCC power " - "value: %i\n", state->Vcc); + "%s called with invalid VCC power value: %i\n", + __func__, state->Vcc); return -EINVAL; } @@ -369,8 +368,9 @@ static int pd6729_set_socket(struct pcmcia_socket *sock, socket_state_t *state) reg |= I365_VPP1_12V; break; default: - dev_dbg(&sock->dev, "pd6729: pd6729_set_socket called with " - "invalid VPP power value: %i\n", state->Vpp); + dev_dbg(&sock->dev, + "%s called with invalid VPP power value: %i\n", + __func__, state->Vpp); return -EINVAL; } @@ -597,8 +597,7 @@ static u_int pd6729_isa_scan(void) int i; if (irq_mode == 1) { - printk(KERN_INFO "pd6729: PCI card interrupts, " - "PCI status changes\n"); + pr_info("PCI card interrupts, PCI status changes\n"); return 0; } @@ -641,15 +640,15 @@ static int pd6729_pci_probe(struct pci_dev *dev, } if (!pci_resource_start(dev, 0)) { - dev_warn(&dev->dev, "refusing to load the driver as the " - "io_base is NULL.\n"); + dev_warn(&dev->dev, + "refusing to load the driver as the io_base is NULL.\n"); ret = -ENOMEM; goto err_out_disable; } - dev_info(&dev->dev, "Cirrus PD6729 PCI to PCMCIA Bridge at 0x%llx " - "on irq %d\n", - (unsigned long long)pci_resource_start(dev, 0), dev->irq); + dev_info(&dev->dev, + "Cirrus PD6729 PCI to PCMCIA Bridge at 0x%llx on irq %d\n", + (unsigned long long)pci_resource_start(dev, 0), dev->irq); /* * Since we have no memory BARs some firmware may not * have had PCI_COMMAND_MEMORY enabled, yet the device needs it. -- 2.13.0 From elfring at users.sourceforge.net Mon May 15 07:03:38 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 16:03:38 +0200 Subject: [PATCH 2/2] pcmcia: Delete an error message for a failed memory allocation in two functions In-Reply-To: <0d48eee5-11d8-e44e-8c11-6370ae7a7ea1@users.sourceforge.net> References: <0d48eee5-11d8-e44e-8c11-6370ae7a7ea1@users.sourceforge.net> Message-ID: <735d7330-c00d-618f-54c2-ddf54f3e06cc@users.sourceforge.net> From: Markus Elfring Date: Mon, 15 May 2017 15:23:42 +0200 Omit an extra message for a memory allocation failure in these functions. This issue was detected by using the Coccinelle software. Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf Signed-off-by: Markus Elfring --- drivers/pcmcia/rsrc_nonstatic.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 2e03dd8f1157..7b5bc6f6f496 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -124,7 +124,6 @@ static int add_interval(struct resource_map *map, u_long base, u_long num) - if (!q) { - printk(KERN_WARNING "out of memory to update resources\n"); + if (!q) return -ENOMEM; - } + q->base = base; q->num = num; q->next = p->next; p->next = q; return 0; @@ -162,7 +161,6 @@ static int sub_interval(struct resource_map *map, u_long base, u_long num) - if (!p) { - printk(KERN_WARNING "out of memory to update resources\n"); + if (!p) return -ENOMEM; - } + p->base = base+num; p->num = q->base+q->num - p->base; q->num = base - q->base; -- 2.13.0 From elfring at users.sourceforge.net Mon May 15 07:00:33 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 16:00:33 +0200 Subject: [PATCH 0/2] PCMCIA-Resource management: Adjustments for three function implementations Message-ID: <0d48eee5-11d8-e44e-8c11-6370ae7a7ea1@users.sourceforge.net> From: Markus Elfring Date: Mon, 15 May 2017 15:46:54 +0200 Two update suggestions were taken into account from static source code analysis. Markus Elfring (2): Improve a size determination in three functions Delete an error message for a failed memory allocation in two functions drivers/pcmcia/rsrc_nonstatic.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) -- 2.13.0 From elfring at users.sourceforge.net Mon May 15 07:02:20 2017 From: elfring at users.sourceforge.net (SF Markus Elfring) Date: Mon, 15 May 2017 16:02:20 +0200 Subject: [PATCH 1/2] pcmcia: Improve a size determination in three functions In-Reply-To: <0d48eee5-11d8-e44e-8c11-6370ae7a7ea1@users.sourceforge.net> References: <0d48eee5-11d8-e44e-8c11-6370ae7a7ea1@users.sourceforge.net> Message-ID: <8be57460-344a-8393-9300-8ef164784a0c@users.sourceforge.net> From: Markus Elfring Date: Mon, 15 May 2017 15:13:00 +0200 Replace the specification of three 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 --- drivers/pcmcia/rsrc_nonstatic.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 5ef7b46a2578..2e03dd8f1157 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -120,5 +120,5 @@ static int add_interval(struct resource_map *map, u_long base, u_long num) if ((p->next == map) || (p->next->base > base+num-1)) break; } - q = kmalloc(sizeof(struct resource_map), GFP_KERNEL); + q = kmalloc(sizeof(*q), GFP_KERNEL); if (!q) { @@ -158,6 +158,5 @@ static int sub_interval(struct resource_map *map, u_long base, u_long num) q->num = base - q->base; } else { /* Split the block into two pieces */ - p = kmalloc(sizeof(struct resource_map), - GFP_KERNEL); + p = kmalloc(sizeof(*p), GFP_KERNEL); if (!p) { @@ -1018,7 +1017,7 @@ static int nonstatic_init(struct pcmcia_socket *s) { struct socket_data *data; - data = kzalloc(sizeof(struct socket_data), GFP_KERNEL); + data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; -- 2.13.0