fpga: dfl: Use struct_size() in kzalloc()
Subsystems (2)
PATCH 1/1 fpga: dfl: Use struct_size() in kzalloc()
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. Also, remove unnecessary function dfl_feature_platform_data_size().
This code was detected with the help of Coccinelle and, audited and fixed manually.
Signed-off-by Gustavo A. R. Silva <[email protected]>
--- drivers/fpga/dfl.c | 3 +-- drivers/fpga/dfl.h | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-)
drivers/fpga/dfl.c +1 -2
@@ -487,8 +487,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)* it will be automatically freed by device's release() callback, * platform_device_release(). */ - pdata =kzalloc (dfl_feature_platform_data_size (binfo->feature_num), -GFP_KERNEL ); + pdata =kzalloc (struct_size (pdata, features, binfo->feature_num),GFP_KERNEL );if (!pdata)return -ENOMEM ;
drivers/fpga/dfl.h +0 -6
@@ -299,12 +299,6 @@ struct dfl_feature_ops {#define DFL_FPGA_FEATURE_DEV_FME "dfl-fme"#define DFL_FPGA_FEATURE_DEV_PORT "dfl-port" -static inline int dfl_feature_platform_data_size (const int num) -{ -return sizeof (struct dfl_feature_platform_data ) + - num *sizeof (struct dfl_feature ); -} -void dfl_fpga_dev_feature_uinit (struct platform_device *pdev);int dfl_fpga_dev_feature_init (struct platform_device *pdev,struct dfl_feature_driver *feature_drvs);
Signature · 1 line
2.27.0
Quoted 47 lines · Gustavo A. R. Silva
Make use of the
struct_size()helper instead of an open-coded version in order to avoid any potential type mistakes. Also, remove unnecessary functiondfl_feature_platform_data_size().This code was detected with the help of Coccinelle and, audited and fixed manually.
Signed-off-by Gustavo A. R. Silva <[email protected]>--- drivers/fpga/dfl.c | 3 +-- drivers/fpga/dfl.h | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-)drivers/fpga/dfl.c +1
-2@@ -487,8 +487,7 @@ static int build_info_commit_dev(struct build_feature_devs_info *binfo)* it will be automatically freed by device's release() callback, * platform_device_release(). */ - pdata =kzalloc (dfl_feature_platform_data_size (binfo->feature_num), -GFP_KERNEL ); + pdata =kzalloc (struct_size (pdata, features, binfo->feature_num),GFP_KERNEL );if (!pdata)return -ENOMEM ;drivers/fpga/dfl.h +0
-6@@ -299,12 +299,6 @@ struct dfl_feature_ops {#define DFL_FPGA_FEATURE_DEV_FME "dfl-fme"#define DFL_FPGA_FEATURE_DEV_PORT "dfl-port" -static inline int dfl_feature_platform_data_size (const int num) -{ -return sizeof (struct dfl_feature_platform_data ) + - num *sizeof (struct dfl_feature ); -} -void dfl_fpga_dev_feature_uinit (struct platform_device *pdev);int dfl_fpga_dev_feature_init (struct platform_device *pdev,struct dfl_feature_driver *feature_drvs);Signature · 1 line
2.27.0
Applied to for-next,
Thanks!