All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH 04/12] hwmon: (mc13783-adc) Increase size of name string
Date: Sat, 14 Sep 2013 18:00:26 +0000	[thread overview]
Message-ID: <20130914200026.268cee58@endymion.delvare> (raw)
In-Reply-To: <1379147615-7703-5-git-send-email-linux@roeck-us.net>

On Sat, 14 Sep 2013 01:33:27 -0700, Guenter Roeck wrote:
> smatch complains about
> 
> mc13783_adc_probe() error: snprintf() chops off the last chars of
> 'id->name': 20 +vs 10
> 
> Use PLATFORM_NAME_SIZE instead of '10' as size when declaring
> the name variable.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Note that Dan Carpenter had been sending the same patch 19 months ago:

http://lists.lm-sensors.org/pipermail/lm-sensors/2012-February/035178.html

I wasn't sure what to do with it and finally forgot about it, sorry.

> ---
>  drivers/hwmon/mc13783-adc.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c
> index 982d862..ae00e60 100644
> --- a/drivers/hwmon/mc13783-adc.c
> +++ b/drivers/hwmon/mc13783-adc.c
> @@ -37,7 +37,7 @@
>  struct mc13783_adc_priv {
>  	struct mc13xxx *mc13xxx;
>  	struct device *hwmon_dev;
> -	char name[10];
> +	char name[PLATFORM_NAME_SIZE];
>  };
>  
>  static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute

I admit I find it a bit sad to allocate more memory than we need just
to make a static analyzer happy. Static analyzers are supposed to help
developers improve their code, not make it less efficient.

That being said, I tried to rewrite the code in a way which was more
obviously correct (to a static analyzer), but what I came up with was
not very appealing.

So if everybody is OK with the simple buffer size fix above, then so am
I.

-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

  reply	other threads:[~2013-09-14 18:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-14  8:33 [lm-sensors] [PATCH 04/12] hwmon: (mc13783-adc) Increase size of name string Guenter Roeck
2013-09-14 18:00 ` Jean Delvare [this message]
2013-09-14 19:33 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130914200026.268cee58@endymion.delvare \
    --to=khali@linux-fr.org \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.