Skip to contentSkip to conversation

Input: imx_keypad - use the preferred form for passing a size of a struct

PATCH Applied Fabio Estevam 2 participants 2 messages Dec 30, 2014 – Jan 4, 2015

Subsystems (3)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/1 Input: imx_keypad - use the preferred form for passing a size of a struct

From: Fabio Estevam <[email protected]>

According to Documentation/CodingStyle - Chapter 14:

"The preferred form for passing a size of a struct is the following:

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

The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not."

So do it as recommeded.

---
 drivers/input/keyboard/imx_keypad.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/keyboard/imx_keypad.c +1 -2
index e53f232..2e855e6 100644
@@ -448,8 +448,7 @@ static int imx_keypad_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	keypad = devm_kzalloc(&pdev->dev, sizeof(struct imx_keypad),
-			      GFP_KERNEL);
+	keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL);
 	if (!keypad) {
 		dev_err(&pdev->dev, "not enough memory for driver data\n");
 		return -ENOMEM;
Signature · 1 line
1.9.1
maintainer Applied
#1 lore raw
Quoted 8 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

According to Documentation/CodingStyle - Chapter 14:

"The preferred form for passing a size of a struct is the following:

        p = kmalloc(sizeof(*p), ...);
Quoted 7 lines

The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not."

So do it as recommeded.

Applied, thank you.

Quoted 21 lines
---
 drivers/input/keyboard/imx_keypad.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/keyboard/imx_keypad.c +1 -2
index e53f232..2e855e6 100644
@@ -448,8 +448,7 @@ static int imx_keypad_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	keypad = devm_kzalloc(&pdev->dev, sizeof(struct imx_keypad),
-			      GFP_KERNEL);
+	keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL);
 	if (!keypad) {
 		dev_err(&pdev->dev, "not enough memory for driver data\n");
 		return -ENOMEM;
Signature · 1 line
1.9.1
Signature · 1 line
Dmitry