Message ID | 20240821064958.4059221-1-yujiaoliang@vivo.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v1] pinctrl: nomadik: Use kmemdup_array instead of kmemdup for multiple allocation | expand |
On Wed, Aug 21, 2024 at 02:49:58PM +0800, Yu Jiaoliang wrote: > Let the kememdup_array() take care about multiplication and possible kmemdup_array() > overflows. ... > + dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs), > + GFP_KERNEL); I would even make this a single line. ... > + dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs), > + GFP_KERNEL); Ditto.
在 2024/8/23 23:27, Andy Shevchenko 写道: > [Some people who received this message don't often get email from andriy.shevchenko@intel.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] > > On Wed, Aug 21, 2024 at 02:49:58PM +0800, Yu Jiaoliang wrote: >> Let the kememdup_array() take care about multiplication and possible > kmemdup_array() > >> overflows. > ... > >> + dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs), >> + GFP_KERNEL); > I would even make this a single line. > > ... > >> + dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs), >> + GFP_KERNEL); > > Ditto. > > -- > With Best Regards, > Andy Shevchenko > > Hi Andy, I have reformatted the code and submitted patch v2. Thank you. Best Regards, Yu
diff --git a/drivers/pinctrl/nomadik/pinctrl-abx500.c b/drivers/pinctrl/nomadik/pinctrl-abx500.c index 47f62c89955a..586ed303916e 100644 --- a/drivers/pinctrl/nomadik/pinctrl-abx500.c +++ b/drivers/pinctrl/nomadik/pinctrl-abx500.c @@ -716,8 +716,8 @@ static int abx500_dt_add_map_configs(struct pinctrl_map **map, if (*num_maps == *reserved_maps) return -ENOSPC; - dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs), - GFP_KERNEL); + dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs), + GFP_KERNEL); if (!dup_configs) return -ENOMEM; diff --git a/drivers/pinctrl/nomadik/pinctrl-nomadik.c b/drivers/pinctrl/nomadik/pinctrl-nomadik.c index fa78d5ecc685..800eba550cfd 100644 --- a/drivers/pinctrl/nomadik/pinctrl-nomadik.c +++ b/drivers/pinctrl/nomadik/pinctrl-nomadik.c @@ -601,8 +601,8 @@ static int nmk_dt_add_map_configs(struct pinctrl_map **map, if (*num_maps == *reserved_maps) return -ENOSPC; - dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs), - GFP_KERNEL); + dup_configs = kmemdup_array(configs, num_configs, sizeof(*dup_configs), + GFP_KERNEL); if (!dup_configs) return -ENOMEM;
Let the kememdup_array() take care about multiplication and possible overflows. Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com> --- drivers/pinctrl/nomadik/pinctrl-abx500.c | 4 ++-- drivers/pinctrl/nomadik/pinctrl-nomadik.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)