2017-12-28 21:45:01

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] PCMCIA-CIS: Adjustments for six function implementations

From: Markus Elfring <[email protected]>
Date: Thu, 28 Dec 2017 22:42:10 +0100

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

Markus Elfring (3):
cistpl: Delete error messages for a failed memory allocation
in three functions
cis: Delete an error message for a failed memory allocation
in two functions
cis: Improve a size determination in pcmcia_loop_config()

drivers/pcmcia/cistpl.c | 12 ++++--------
drivers/pcmcia/pcmcia_cis.c | 11 ++++-------
2 files changed, 8 insertions(+), 15 deletions(-)

--
2.15.1


2017-12-28 21:46:03

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] pcmcia/cistpl: Delete error messages for a failed memory allocation in three functions

From: Markus Elfring <[email protected]>
Date: Thu, 28 Dec 2017 22:12:00 +0100

Omit extra messages for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/pcmcia/cistpl.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 102646fedb56..192c0e8e9c3d 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -379,10 +379,9 @@ int verify_cis_cache(struct pcmcia_socket *s)
return -EINVAL;

buf = kmalloc(256, GFP_KERNEL);
- if (buf == NULL) {
- dev_warn(&s->dev, "no memory for verifying CIS\n");
+ if (!buf)
return -ENOMEM;
- }
+
mutex_lock(&s->ops_mutex);
list_for_each_entry(cis, &s->cis_cache, node) {
int len = cis->len;
@@ -419,7 +418,6 @@ int pcmcia_replace_cis(struct pcmcia_socket *s,
kfree(s->fake_cis);
s->fake_cis = kmalloc(len, GFP_KERNEL);
if (s->fake_cis == NULL) {
- dev_warn(&s->dev, "no memory to replace CIS\n");
mutex_unlock(&s->ops_mutex);
return -ENOMEM;
}
@@ -1395,14 +1393,12 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
mutex_unlock(&s->ops_mutex);

tuple = kmalloc(sizeof(*tuple), GFP_KERNEL);
- if (tuple == NULL) {
- dev_warn(&s->dev, "no memory to validate CIS\n");
+ if (!tuple)
return -ENOMEM;
- }
+
p = kmalloc(sizeof(*p), GFP_KERNEL);
if (p == NULL) {
kfree(tuple);
- dev_warn(&s->dev, "no memory to validate CIS\n");
return -ENOMEM;
}

--
2.15.1

2017-12-28 21:47:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] pcmcia/cis: Delete an error message for a failed memory allocation in two functions

From: Markus Elfring <[email protected]>
Date: Thu, 28 Dec 2017 22:20:51 +0100

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/pcmcia/pcmcia_cis.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/pcmcia/pcmcia_cis.c b/drivers/pcmcia/pcmcia_cis.c
index 1c05d74e850d..ffcd014b7bc1 100644
--- a/drivers/pcmcia/pcmcia_cis.c
+++ b/drivers/pcmcia/pcmcia_cis.c
@@ -43,10 +43,9 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
int ret;

buf = kmalloc(256, GFP_KERNEL);
- if (buf == NULL) {
- dev_warn(&s->dev, "no memory to read tuple\n");
+ if (!buf)
return -ENOMEM;
- }
+
tuple.DesiredTuple = code;
tuple.Attributes = 0;
if (function == BIND_FN_ALL)
@@ -93,10 +92,8 @@ int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
int ret;

buf = kzalloc(256, GFP_KERNEL);
- if (buf == NULL) {
- dev_warn(&s->dev, "no memory to read tuple\n");
+ if (!buf)
return -ENOMEM;
- }

tuple.TupleData = buf;
tuple.TupleDataMax = 255;
--
2.15.1

2017-12-28 21:48:36

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] pcmcia/cis: Improve a size determination in pcmcia_loop_config()

From: Markus Elfring <[email protected]>
Date: Thu, 28 Dec 2017 22:30:42 +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/pcmcia/pcmcia_cis.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pcmcia/pcmcia_cis.c b/drivers/pcmcia/pcmcia_cis.c
index ffcd014b7bc1..ecee94e8f30a 100644
--- a/drivers/pcmcia/pcmcia_cis.c
+++ b/drivers/pcmcia/pcmcia_cis.c
@@ -264,7 +264,7 @@ int pcmcia_loop_config(struct pcmcia_device *p_dev,
struct pcmcia_cfg_mem *cfg_mem;
int ret;

- cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
+ cfg_mem = kzalloc(sizeof(*cfg_mem), GFP_KERNEL);
if (cfg_mem == NULL)
return -ENOMEM;

--
2.15.1