drivers: mfd: fix off by one error
Subsystems (2)
PATCH 1/1 drivers: mfd: fix off by one error
snprintf() is overflowed iff result is greater or equal than argument "size".
---
Compile tested.
drivers/mfd/mc13xxx-core.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mfd/mc13xxx-core.c +1 -1
@@ -696,7 +696,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, };/* there is no asnprintf in the kernel :-( */ -if (snprintf (buf,sizeof (buf), format, name) >sizeof (buf)) +if (snprintf (buf,sizeof (buf), format, name) >=sizeof (buf))return -E2BIG ; cell.name =kmemdup (buf,strlen (buf) +1 ,GFP_KERNEL );
Signature · 1 line
1.7.0.4
PATCH 1/1 mfd/mc13xxx: don't open code kasprintf
This fixes an off by one error noticed by Vasiliy Kulikov en passant.
--- drivers/mfd/mc13xxx-core.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)
drivers/mfd/mc13xxx-core.c +1 -6
@@ -687,7 +687,6 @@ EXPORT_SYMBOL_GPL(mc13783_adc_do_conversion);static int mc13xxx_add_subdevice_pdata (struct mc13xxx *mc13xxx,const char *format,void *pdata,size_t pdata_size) { -char buf[30 ];const char *name =mc13xxx_get_chipname (mc13xxx);struct mfd_cell cell = {
@@ -695,11 +694,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, .data_size = pdata_size, }; -/* there is no asnprintf in the kernel :-( */ -if (snprintf (buf,sizeof (buf), format, name) >sizeof (buf)) -return -E2BIG ; - - cell.name =kmemdup (buf,strlen (buf) +1 ,GFP_KERNEL ); + cell.name =kasprintf (GFP_KERNEL , format, name);if (!cell.name)return -ENOMEM ;
Signature · 6 lines
1.7.2.3 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] mfd/mc13xxx: don't open code kasprintf
Hi Samuel,
would you mind to take this patch (or squash it into 0c9b33e5a23e2053165c9e30ffff3b3a3cf1b2b8)?
Thanks
Uwe
Quoted 36 lines · Uwe Kleine-König
This fixes an off by one error noticed by Vasiliy Kulikov en passant.
Signed-off-by Uwe Kleine-König <[email protected]>--- drivers/mfd/mc13xxx-core.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)drivers/mfd/mc13xxx-core.c +1
-6@@ -687,7 +687,6 @@ EXPORT_SYMBOL_GPL(mc13783_adc_do_conversion);static int mc13xxx_add_subdevice_pdata (struct mc13xxx *mc13xxx,const char *format,void *pdata,size_t pdata_size) { -char buf[30 ];const char *name =mc13xxx_get_chipname (mc13xxx);struct mfd_cell cell = {@@ -695,11 +694,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, .data_size = pdata_size, }; -/* there is no asnprintf in the kernel :-( */ -if (snprintf (buf,sizeof (buf), format, name) >sizeof (buf)) -return -E2BIG ; - - cell.name =kmemdup (buf,strlen (buf) +1 ,GFP_KERNEL ); + cell.name =kasprintf (GFP_KERNEL , format, name);if (!cell.name)return -ENOMEM ;Signature · 1 line
1.7.2.3
Signature · 6 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] mfd/mc13xxx: don't open code kasprintf
In reply to Uwe Kleine-KönigHi Uwe,
Quoted 20 lines · Uwe Kleine-König
This fixes an off by one error noticed by Vasiliy Kulikov en passant.
Signed-off-by Uwe Kleine-König <[email protected]>--- drivers/mfd/mc13xxx-core.c | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-)drivers/mfd/mc13xxx-core.c +0
-1@@ -687,7 +687,6 @@ EXPORT_SYMBOL_GPL(mc13783_adc_do_conversion);static int mc13xxx_add_subdevice_pdata (struct mc13xxx *mc13xxx,const char *format,void *pdata,size_t pdata_size) { -char buf[30 ];const char *name =mc13xxx_get_chipname (mc13xxx);struct mfd_cell cell = {
drivers/mfd/mc13xxx-core.c static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, · line 697
Quoted 9 lines
drivers/mfd/mc13xxx-core.c +1
-5@@ -695,11 +694,7 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, .data_size = pdata_size, }; -/* there is no asnprintf in the kernel :-( */ -if (snprintf (buf,sizeof (buf), format, name) >sizeof (buf)) -return -E2BIG ; - - cell.name =kmemdup (buf,strlen (buf) +1 ,GFP_KERNEL ); + cell.name =kasprintf (GFP_KERNEL , format, name);
I don't think you need to allocate a name pointer here. cell.name = mc13xxx_get_chipname(mc13xxx); should be enough as platform_device_alloc() will memcpy it into an allocated buffer.
Cheers,
Samuel.
Quoted 6 lines
drivers/mfd/mc13xxx-core.c +0
-0if (!cell.name)return -ENOMEM ;Signature · 1 line
1.7.2.3
Signature · 6 lines
Intel Open Source Technology Centre http://oss.intel.com/ -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html