Skip to contentSkip to conversation

drivers: mfd: sec-code: Fix sizeof argument

PATCH In review Leon Romanovsky 3 participants 5 messages May 15, 2013 – May 17, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: mfd: sec-code: Fix sizeof argument

---
 drivers/mfd/sec-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/sec-core.c +1 -1
index 77ee26ef..5b740a3 100644
@@ -121,7 +121,7 @@ static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
 {
 	struct sec_platform_data *pd;
 
-	pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+	pd = devm_kzalloc(dev, sizeof(struct sec_platform_data), GFP_KERNEL);
 	if (!pd) {
 		dev_err(dev, "could not allocate memory for pdata\n");
 		return ERR_PTR(-ENOMEM);
Signature · 1 line
1.8.1.5
#1 lore raw

Hi Leon,

Quoted 10 lines · Leon Romanovsky
---
 drivers/mfd/sec-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/sec-core.c +0 -0
index 77ee26ef..5b740a3 100644

drivers/mfd/sec-core.c static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( · line 124

Quoted 5 lines
drivers/mfd/sec-core.c +1 -1
@@ -121,7 +121,7 @@ static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
 {
 	struct sec_platform_data *pd;
 
-	pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+	pd = devm_kzalloc(dev, sizeof(struct sec_platform_data), GFP_KERNEL);

How is that fixing anything ?

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#2 lore raw
Quoted 16 lines · Samuel Ortiz

Hi Leon,

Quoted 13 lines · Leon Romanovsky
---
 drivers/mfd/sec-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/sec-core.c +0 -0
index 77ee26ef..5b740a3 100644
@@ -121,7 +121,7 @@ static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(
 {
      struct sec_platform_data *pd;
 
Quoted 3 lines

drivers/mfd/sec-core.c static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( · line 124

Quoted 2 lines
drivers/mfd/sec-core.c +1 -1
-     pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+     pd = devm_kzalloc(dev, sizeof(struct sec_platform_data), GFP_KERNEL);

How is that fixing anything ?

Technically you are right, this fix brings code to be align to common code convention and allows to automatic tools correctly parse it.

Quoted 7 lines

Cheers,
Samuel.

--
Intel Open Source Technology Centre
http://oss.intel.com/

--
Leon Romanovsky | Independent Linux Consultant
www.leon.nu | [email protected]

#3 lore raw
Quoted 3 lines · Leon Romanovsky
Quoted 2 lines · Samuel Ortiz

drivers/mfd/sec-core.c

Quoted 1 line · Leon Romanovsky
drivers/mfd/sec-core.c +0 -0

[]

Quoted 1 line
Quoted 1 line

drivers/mfd/sec-core.c static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(

Quoted 1 line
drivers/mfd/sec-core.c +0 -0
@@ -121,7 +121,7 @@ static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(

[]

Quoted 5 lines
Quoted 3 lines

drivers/mfd/sec-core.c static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( · line 124

Quoted 2 lines
drivers/mfd/sec-core.c +1 -1
-     pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+     pd = devm_kzalloc(dev, sizeof(struct sec_platform_data), GFP_KERNEL);

How is that fixing anything ?

Technically you are right, this fix brings code to be align to common code convention and allows to automatic tools correctly parse it.

Not really.
Common coding convention is actually the original code.

from: Documentation/CodingStyle:

Chapter 14: Allocating memory
[]
The preferred form for passing a size of a struct is the following:

	p = kmalloc(sizeof(*p), ...);
#4 lore raw
Quoted 16 lines · Joe Perches
Quoted 3 lines · Leon Romanovsky
Quoted 2 lines · Samuel Ortiz

drivers/mfd/sec-core.c

Quoted 1 line · Leon Romanovsky
drivers/mfd/sec-core.c +0 -0

[]

Quoted 1 line
Quoted 1 line

drivers/mfd/sec-core.c static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(

Quoted 1 line
drivers/mfd/sec-core.c +0 -0
@@ -121,7 +121,7 @@ static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata(

[]

Quoted 5 lines
Quoted 3 lines

drivers/mfd/sec-core.c static struct sec_platform_data *sec_pmic_i2c_parse_dt_pdata( · line 124

Quoted 2 lines
drivers/mfd/sec-core.c +1 -1
-     pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
+     pd = devm_kzalloc(dev, sizeof(struct sec_platform_data), GFP_KERNEL);

How is that fixing anything ?

Technically you are right, this fix brings code to be align to common code convention and allows to automatic tools correctly parse it.

Not really.
Common coding convention is actually the original code.

Quoted 9 lines

from: Documentation/CodingStyle:

Chapter 14: Allocating memory
[]
The preferred form for passing a size of a struct is the following:

        p = kmalloc(sizeof(*p), ...);

Thanks Joe, it is good to know, but from my simple grep, most developers doesn't follow with this guide:
leon@tux ~/dev/kernel/linux-staging $ grep -r "sizeof(struct" * | wc -l 25865
leon@tux ~/dev/kernel/linux-staging $ grep -r "sizeof(\*" * | wc -l 14568

--
Leon Romanovsky | Independent Linux Consultant
www.leon.nu | [email protected]