RE: [PATCH v1 2/7] extcon: Switch to use kasprintf() instead of open coded

From: David Laight
Date: Wed Aug 29 2018 - 05:38:56 EST


From: Andy Shevchenko
> Sent: 27 August 2018 16:36
>
> Switch to use kasprintf() instead of open coded variant.
> No functional change intended.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
> drivers/extcon/extcon.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index c21650a92689..5ab0498be652 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -1123,7 +1123,6 @@ int extcon_dev_register(struct extcon_dev *edev)
> (unsigned long)atomic_inc_return(&edev_no));
>
> if (edev->max_supported) {
> - char buf[10];
> char *str;
> struct extcon_cable *cable;
>
> @@ -1137,9 +1136,7 @@ int extcon_dev_register(struct extcon_dev *edev)
> for (index = 0; index < edev->max_supported; index++) {
> cable = &edev->cables[index];
>
> - snprintf(buf, 10, "cable.%d", index);
> - str = kzalloc(strlen(buf) + 1,
> - GFP_KERNEL);
> + str = kasprintf(GFP_KERNEL, "cable.%d", index);

Hmmm... Why now just allocate the space for the string in the
'extcon_cable' structure.
(Then work out how to stop gcc complaining there isn't room
for 4G cables ...)

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)