Skip to contentSkip to conversation

staging: ccree: remove unnecessary cast on kmalloc

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Jul 9, 2017 – Jul 11, 2017

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

PATCH 1/2 staging: ccree: remove unnecessary cast on kmalloc

The assignment operator implicitly converts a void pointer to the type of the pointer it is assigned to.

This issue was detected using Coccinelle and the following semantic patch:

@@
expression * e;
expression arg1, arg2;
type T;
@@

- e=(T*)
+ e=
kmalloc(arg1, arg2);

---
 drivers/staging/ccree/ssi_buffer_mgr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/ccree/ssi_buffer_mgr.c +1 -2
index b35871e..18a8694 100644
@@ -1725,8 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
 	struct buff_mgr_handle *buff_mgr_handle;
 	struct device *dev = &drvdata->plat_dev->dev;
 
-	buff_mgr_handle = (struct buff_mgr_handle *)
-		kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
+	buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
 	if (!buff_mgr_handle)
 		return -ENOMEM;
 
Signature · 1 line
2.5.0
#1 lore raw

PATCH 2/2 staging: ccree: use sizeof(*var) in kmalloc

Fix the following checkpatch warning:

CHECK: Prefer kmalloc(sizeof(*buff_mgr_handle)...) over kmalloc(sizeof(struct buff_mgr_handle)...)

---
 drivers/staging/ccree/ssi_buffer_mgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/ccree/ssi_buffer_mgr.c +1 -1
index 18a8694..9caff9b 100644
@@ -1725,7 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
 	struct buff_mgr_handle *buff_mgr_handle;
 	struct device *dev = &drvdata->plat_dev->dev;
 
-	buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
+	buff_mgr_handle = kmalloc(sizeof(*buff_mgr_handle), GFP_KERNEL);
 	if (!buff_mgr_handle)
 		return -ENOMEM;
 
Signature · 1 line
2.5.0
Acked-by on v1 1/2
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 11 lines · Gustavo A. R. Silva

The assignment operator implicitly converts a void pointer to the type of the pointer it is assigned to.

This issue was detected using Coccinelle and the following semantic patch:

@@
expression * e;
expression arg1, arg2;
type T;
@@

Quoted 5 lines

- e=(T*)
+ e=
kmalloc(arg1, arg2);

For both patches:

Quoted 19 lines
---
 drivers/staging/ccree/ssi_buffer_mgr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/ccree/ssi_buffer_mgr.c +1 -3
index b35871e..18a8694 100644
@@ -1725,8 +1725,7 @@ int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
        struct buff_mgr_handle *buff_mgr_handle;
        struct device *dev = &drvdata->plat_dev->dev;
 
-       buff_mgr_handle = (struct buff_mgr_handle *)
-               kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
+       buff_mgr_handle = kmalloc(sizeof(struct buff_mgr_handle), GFP_KERNEL);
        if (!buff_mgr_handle)
                return -ENOMEM;
 
--
Quoted 2 lines

2.5.0

Thanks,
Gilad

Signature · 6 lines
Gilad Ben-Yossef
Chief Coffee Drinker

"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
 -- Jean-Baptiste Queru