2018-01-08 16:10:53

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/4] misc-IOC4: Adjustments for ioc4_probe()

From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 17:01:23 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
Return -ENOMEM after a failed kmalloc()
Delete an error message for a failed memory allocation
Improve a size determination
Adjust one function call together with a variable assignment

drivers/misc/ioc4.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

--
2.15.1



2018-01-08 16:15:19

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/4] misc/ioc4: Return -ENOMEM after a failed kmalloc() in ioc4_probe()

From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 16:12:52 +0100

Replace an error code for the indication of a memory allocation failure
in this function.

Fixes: 22329b511a97557b293583194037d1f4c71e1504 ("ioc4: Core driver rewrite")

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/ioc4.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index ec0832278170..63a64104d2da 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -300,7 +300,7 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
printk(KERN_WARNING
"%s: Failed to allocate IOC4 data for pci_dev %s.\n",
__func__, pci_name(pdev));
- ret = -ENODEV;
+ ret = -ENOMEM;
goto out_idd;
}
idd->idd_pdev = pdev;
--
2.15.1

2018-01-08 16:16:57

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/4] misc/ioc4: Delete an error message for a failed memory allocation in ioc4_probe()

From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 16:14:49 +0100

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 <[email protected]>
---
drivers/misc/ioc4.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index 63a64104d2da..5bd422498fff 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -297,9 +297,6 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
/* Set up per-IOC4 data */
idd = kmalloc(sizeof(struct ioc4_driver_data), GFP_KERNEL);
if (!idd) {
- printk(KERN_WARNING
- "%s: Failed to allocate IOC4 data for pci_dev %s.\n",
- __func__, pci_name(pdev));
ret = -ENOMEM;
goto out_idd;
}
--
2.15.1

2018-01-08 16:18:03

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/4] misc/ioc4: Improve a size determination in ioc4_probe()

From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 16:18:52 +0100

Replace the specification of a data structure by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/ioc4.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index 5bd422498fff..704e13382df0 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -295,7 +295,7 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
pci_set_master(pdev);

/* Set up per-IOC4 data */
- idd = kmalloc(sizeof(struct ioc4_driver_data), GFP_KERNEL);
+ idd = kmalloc(sizeof(*idd), GFP_KERNEL);
if (!idd) {
ret = -ENOMEM;
goto out_idd;
--
2.15.1

2018-01-08 16:19:18

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/4] misc/ioc4: Adjust one function call together with a variable assignment

From: Markus Elfring <[email protected]>
Date: Mon, 8 Jan 2018 16:43:21 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code place.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/ioc4.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index 704e13382df0..8381dd9c7dd9 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -283,10 +283,11 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
struct ioc4_driver_data *idd;
struct ioc4_submodule *is;
uint32_t pcmd;
- int ret;

/* Enable IOC4 and take ownership of it */
- if ((ret = pci_enable_device(pdev))) {
+ int ret = pci_enable_device(pdev);
+
+ if (ret) {
printk(KERN_WARNING
"%s: Failed to enable IOC4 device for pci_dev %s.\n",
__func__, pci_name(pdev));
--
2.15.1