Message ID | 20180727073353.25012-1-miquel.raynal@bootlin.com (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | Eduardo Valentin |
Headers | show |
Series | thermal: armada: fix strncpy use | expand |
On Fri, Jul 27, 2018 at 09:33:53AM +0200, Miquel Raynal wrote: > Fix the following warning raised by the kbuild test robot > infrastructure: > > In function 'armada_set_sane_name', > inlined from 'armada_thermal_probe' at drivers/thermal/armada_thermal.c:416:2: > >> drivers/thermal/armada_thermal.c:377:2: warning: 'strncpy' specified bound 20 equals destination size [-Wstringop-truncation] > strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH); > > Reduce the copy length by 1 to avoid this error and ensure the string > is null terminated manually as suggested in the strncpy man page. > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> > --- > > Hello Eduardo, > Sorry for messing with strncpy. If you want, you may squash this patch > with: > "thermal: armada: add a function that sanitizes the thermal zone name" > It should solve the above issue. I will probably just squash this. > Cheers, > Miquèl > > drivers/thermal/armada_thermal.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c > index e493fe33bffb..b5b01cf9b061 100644 > --- a/drivers/thermal/armada_thermal.c > +++ b/drivers/thermal/armada_thermal.c > @@ -777,7 +777,8 @@ static void armada_set_sane_name(struct platform_device *pdev, > } > > /* Save the name locally */ > - strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH); > + strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH - 1); > + priv->zone_name[THERMAL_NAME_LENGTH - 1] = '\0'; > > /* Then check there are no '-' or hwmon core will complain */ > do { > -- > 2.14.1 >
diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index e493fe33bffb..b5b01cf9b061 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -777,7 +777,8 @@ static void armada_set_sane_name(struct platform_device *pdev, } /* Save the name locally */ - strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH); + strncpy(priv->zone_name, name, THERMAL_NAME_LENGTH - 1); + priv->zone_name[THERMAL_NAME_LENGTH - 1] = '\0'; /* Then check there are no '-' or hwmon core will complain */ do {