All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <kernel@jic23.retrosnub.co.uk>
To: "Lothar Waßmann" <LW@KARO-electronics.de>
Cc: Jonathan Cameron <arm@jic23.retrosnub.co.uk>,
	Joe Perches <joe@perches.com>,
	Linus Walleij <linus.walleij@stericsson.com>,
	linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	"Ben Dooks (embedded platforms)" <ben-linux@fluff.org>,
	"Jean Delvare \(PC drivers\, core\)" <khali@linux-fr.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 05/25] drivers/i2c: Use static const char arrays
Date: Tue, 14 Sep 2010 13:57:59 +0100	[thread overview]
Message-ID: <4C8F7157.9060005@jic23.retrosnub.co.uk> (raw)
In-Reply-To: <19599.9719.562406.692216@ipc1.ka-ro>

On 09/14/10 08:36, Lothar Waßmann wrote:
> Hi,
> 
> Jonathan Cameron writes:
>>  Commit message is  somewhat inaccurate...
>>
>> On 09/13/10 20:47, Joe Perches wrote:
>>> Signed-off-by: Joe Perches <joe@perches.com>
>>> ---
>>>  drivers/i2c/busses/i2c-stu300.c |    4 ++--
>>>  1 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
>>> index 495be45..2f7c09c 100644
>>> --- a/drivers/i2c/busses/i2c-stu300.c
>>> +++ b/drivers/i2c/busses/i2c-stu300.c
>>> @@ -871,7 +871,7 @@ stu300_probe(struct platform_device *pdev)
>>>  	struct resource *res;
>>>  	int bus_nr;
>>>  	int ret = 0;
>>> -	char clk_name[] = "I2C0";
>>> +	char clk_name[sizeof("I2Cx")];
>>>  
>>>  	dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL);
>>>  	if (!dev) {
>>> @@ -881,7 +881,7 @@ stu300_probe(struct platform_device *pdev)
>>>  	}
>>>  
>>>  	bus_nr = pdev->id;
>>> -	clk_name[3] += (char)bus_nr;
>>> +	sprintf(clk_name, "I2C%c", '0' + bus_nr);
>> I'm guessing that there are never more than a couple of these.
>> Why is this method a better bet than just putting %d?
>>
> '%c' will only ever produce one byte of output while '%d' may
> produce up to 11 bytes depending on the value of bus_nr thus
> overflowing the buffer.
Then use an snprintf, or apply a check to ensure it isn't bigger than
9.

If you don't mind having clocks named i2c$ or something equally
silly then I guess this is fine.  To my mind, if that is possible
this is a bug that should be fixed rather than avoided.



WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <kernel-tko9wxEg+fIOOJlXag/Snyp2UmYkHbXO@public.gmane.org>
To: "Lothar Waßmann" <LW-bxm8fMRDkQLDiMYJYoSAnRvVK+yQ3ZXh@public.gmane.org>
Cc: Jonathan Cameron
	<arm-tko9wxEg+fIOOJlXag/Snyp2UmYkHbXO@public.gmane.org>,
	Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>,
	Linus Walleij
	<linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Ben Dooks (embedded platforms)"
	<ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
	"Jean Delvare (PC drivers,
	core)" <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH 05/25] drivers/i2c: Use static const char arrays
Date: Tue, 14 Sep 2010 13:57:59 +0100	[thread overview]
Message-ID: <4C8F7157.9060005@jic23.retrosnub.co.uk> (raw)
In-Reply-To: <19599.9719.562406.692216-VjFSrY7JcPWvSplVBqRQBQ@public.gmane.org>

On 09/14/10 08:36, Lothar Waßmann wrote:
> Hi,
> 
> Jonathan Cameron writes:
>>  Commit message is  somewhat inaccurate...
>>
>> On 09/13/10 20:47, Joe Perches wrote:
>>> Signed-off-by: Joe Perches <joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
>>> ---
>>>  drivers/i2c/busses/i2c-stu300.c |    4 ++--
>>>  1 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
>>> index 495be45..2f7c09c 100644
>>> --- a/drivers/i2c/busses/i2c-stu300.c
>>> +++ b/drivers/i2c/busses/i2c-stu300.c
>>> @@ -871,7 +871,7 @@ stu300_probe(struct platform_device *pdev)
>>>  	struct resource *res;
>>>  	int bus_nr;
>>>  	int ret = 0;
>>> -	char clk_name[] = "I2C0";
>>> +	char clk_name[sizeof("I2Cx")];
>>>  
>>>  	dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL);
>>>  	if (!dev) {
>>> @@ -881,7 +881,7 @@ stu300_probe(struct platform_device *pdev)
>>>  	}
>>>  
>>>  	bus_nr = pdev->id;
>>> -	clk_name[3] += (char)bus_nr;
>>> +	sprintf(clk_name, "I2C%c", '0' + bus_nr);
>> I'm guessing that there are never more than a couple of these.
>> Why is this method a better bet than just putting %d?
>>
> '%c' will only ever produce one byte of output while '%d' may
> produce up to 11 bytes depending on the value of bus_nr thus
> overflowing the buffer.
Then use an snprintf, or apply a check to ensure it isn't bigger than
9.

If you don't mind having clocks named i2c$ or something equally
silly then I guess this is fine.  To my mind, if that is possible
this is a bug that should be fixed rather than avoided.

WARNING: multiple messages have this Message-ID (diff)
From: kernel@jic23.retrosnub.co.uk (Jonathan Cameron)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 05/25] drivers/i2c: Use static const char arrays
Date: Tue, 14 Sep 2010 13:57:59 +0100	[thread overview]
Message-ID: <4C8F7157.9060005@jic23.retrosnub.co.uk> (raw)
In-Reply-To: <19599.9719.562406.692216@ipc1.ka-ro>

On 09/14/10 08:36, Lothar Wa?mann wrote:
> Hi,
> 
> Jonathan Cameron writes:
>>  Commit message is  somewhat inaccurate...
>>
>> On 09/13/10 20:47, Joe Perches wrote:
>>> Signed-off-by: Joe Perches <joe@perches.com>
>>> ---
>>>  drivers/i2c/busses/i2c-stu300.c |    4 ++--
>>>  1 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
>>> index 495be45..2f7c09c 100644
>>> --- a/drivers/i2c/busses/i2c-stu300.c
>>> +++ b/drivers/i2c/busses/i2c-stu300.c
>>> @@ -871,7 +871,7 @@ stu300_probe(struct platform_device *pdev)
>>>  	struct resource *res;
>>>  	int bus_nr;
>>>  	int ret = 0;
>>> -	char clk_name[] = "I2C0";
>>> +	char clk_name[sizeof("I2Cx")];
>>>  
>>>  	dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL);
>>>  	if (!dev) {
>>> @@ -881,7 +881,7 @@ stu300_probe(struct platform_device *pdev)
>>>  	}
>>>  
>>>  	bus_nr = pdev->id;
>>> -	clk_name[3] += (char)bus_nr;
>>> +	sprintf(clk_name, "I2C%c", '0' + bus_nr);
>> I'm guessing that there are never more than a couple of these.
>> Why is this method a better bet than just putting %d?
>>
> '%c' will only ever produce one byte of output while '%d' may
> produce up to 11 bytes depending on the value of bus_nr thus
> overflowing the buffer.
Then use an snprintf, or apply a check to ensure it isn't bigger than
9.

If you don't mind having clocks named i2c$ or something equally
silly then I guess this is fine.  To my mind, if that is possible
this is a bug that should be fixed rather than avoided.

  reply	other threads:[~2010-09-14 12:58 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-13 19:47 [PATCH 00/25] treewide-next: Use static const char arrays Joe Perches
2010-09-13 19:47 ` Joe Perches
2010-09-13 19:47 ` Joe Perches
2010-09-13 19:47 ` Joe Perches
2010-09-13 19:47 ` [PATCH 01/25] arch/mips: " Joe Perches
2010-09-18 22:54   ` Ralf Baechle
2010-09-18 23:44     ` Joe Perches
2010-09-13 19:47 ` [PATCH 02/25] arch/powerpc: " Joe Perches
2010-09-13 19:47   ` Joe Perches
2010-09-14  2:02   ` Stephen Rothwell
2010-09-14  2:02     ` Stephen Rothwell
2010-09-14  2:04   ` Stephen Rothwell
2010-09-14  2:04     ` Stephen Rothwell
2010-09-13 19:47 ` [PATCH 03/25] drivers/acpi: " Joe Perches
2010-09-13 19:47 ` [PATCH 04/25] drivers/char: " Joe Perches
2010-09-14  2:06   ` Stephen Rothwell
2010-09-14  2:06     ` Stephen Rothwell
2010-09-13 19:47 ` [PATCH 05/25] drivers/i2c: " Joe Perches
2010-09-13 19:47   ` Joe Perches
2010-09-13 19:47   ` Joe Perches
2010-09-13 19:56   ` Russell King - ARM Linux
2010-09-13 19:56     ` Russell King - ARM Linux
2010-09-13 19:56     ` Russell King - ARM Linux
2010-09-13 20:08   ` Jonathan Cameron
2010-09-13 20:08     ` Jonathan Cameron
2010-09-13 20:08     ` Jonathan Cameron
2010-09-13 20:16     ` Joe Perches
2010-09-13 20:16       ` Joe Perches
2010-09-13 20:16       ` Joe Perches
2010-09-14  7:36     ` Lothar Waßmann
2010-09-14  7:36       ` Lothar Waßmann
2010-09-14  7:36       ` Lothar Waßmann
2010-09-14 12:57       ` Jonathan Cameron [this message]
2010-09-14 12:57         ` Jonathan Cameron
2010-09-14 12:57         ` Jonathan Cameron
2010-09-14 19:48         ` Russell King - ARM Linux
2010-09-14 19:48           ` Russell King - ARM Linux
2010-09-14 19:48           ` Russell King - ARM Linux
2010-09-14 23:23   ` Ben Dooks
2010-09-14 23:23     ` Ben Dooks
2010-09-14 23:23     ` Ben Dooks
2010-09-13 19:47 ` [PATCH 06/25] drivers/isdn: " Joe Perches
2010-09-13 19:47 ` [PATCH 07/25] drivers/media: " Joe Perches
2010-09-13 21:50   ` Mauro Carvalho Chehab
2010-09-13 22:07     ` [PATCH 07/25] drivers/media/video/zoran: Don't use initialized char array Joe Perches
2010-09-13 19:47 ` [PATCH 08/25] drivers/net/atl1c: Use static const char arrays Joe Perches
2010-09-13 19:47 ` [PATCH 09/25] drivers/net/atl1e: " Joe Perches
2010-09-13 19:47 ` [PATCH 10/25] drivers/net/(intel): " Joe Perches
2010-09-13 19:47   ` Joe Perches
2010-09-13 19:47 ` [PATCH 11/25] drivers/net/netxen: " Joe Perches
2010-09-13 19:47 ` [PATCH 12/25] drivers/net/qlcnic: " Joe Perches
2010-09-13 19:47 ` [PATCH 13/25] drivers/net/spider_net.c: " Joe Perches
2010-09-13 19:47 ` [PATCH 14/25] drivers/net/vnxnet3: " Joe Perches
2010-09-13 19:50   ` [Pv-drivers] " Bhavesh Davda
2010-09-13 20:07   ` Shreyas Bhatewara
2010-09-13 19:47 ` [PATCH 15/25] drivers/net/wireless/ipw2x00: " Joe Perches
2010-09-14 18:41   ` John W. Linville
2010-09-13 19:47 ` [PATCH 16/25] drivers/s390/char: " Joe Perches
2010-09-13 19:47 ` [PATCH 17/25] drivers/scsi: " Joe Perches
2010-09-13 19:47 ` [PATCH 18/25] drivers/serial/suncore.c: " Joe Perches
2010-09-13 19:47   ` Joe Perches
2010-09-13 20:36   ` Alan Cox
2010-09-13 20:36     ` [PATCH 18/25] drivers/serial/suncore.c: Use static const char Alan Cox
2010-09-13 20:22     ` [PATCH 18/25] drivers/serial/suncore.c: Use static const char arrays Joe Perches
2010-09-13 20:22       ` [PATCH 18/25] drivers/serial/suncore.c: Use static const char Joe Perches
2010-09-13 21:11       ` [PATCH 18/25] drivers/serial/suncore.c: Use static const char arrays Nick Bowler
2010-09-13 21:11         ` [PATCH 18/25] drivers/serial/suncore.c: Use static const char Nick Bowler
2010-09-13 21:17         ` [PATCH 18/25] drivers/serial/suncore.c: Use static const char arrays Joe Perches
2010-09-13 21:17           ` [PATCH 18/25] drivers/serial/suncore.c: Use static const char Joe Perches
2010-09-13 19:47 ` [PATCH 19/25] drivers/staging: Use static const char arrays Joe Perches
2010-09-13 19:47 ` [PATCH 20/25] drivers/usb: " Joe Perches
2010-09-13 20:38   ` Greg KH
2010-09-13 19:47 ` [PATCH 21/25] drivers/video: " Joe Perches
2010-09-13 19:47   ` Joe Perches
2010-09-15 19:02   ` James Simmons
2010-09-15 19:02     ` James Simmons
2010-09-13 19:48 ` [PATCH 22/25] net/dsa: " Joe Perches
2010-09-13 19:48 ` [PATCH 23/25] net/sunrpc: " Joe Perches
2010-09-13 19:48 ` [PATCH 24/25] sound: " Joe Perches
2010-09-13 20:30   ` Takashi Iwai
2010-09-13 20:30     ` Takashi Iwai
2010-09-13 20:47     ` Joe Perches
2010-09-13 21:33       ` Takashi Iwai
2010-09-13 21:33         ` Takashi Iwai
2010-09-13 19:48 ` [PATCH 25/25] tools/perf/util: " Joe Perches
2010-09-14  9:14 ` (unknown) David Howells
2010-09-14  9:14   ` (no subject) David Howells
2010-09-14  9:14   ` David Howells

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=4C8F7157.9060005@jic23.retrosnub.co.uk \
    --to=kernel@jic23.retrosnub.co.uk \
    --cc=LW@KARO-electronics.de \
    --cc=arm@jic23.retrosnub.co.uk \
    --cc=ben-linux@fluff.org \
    --cc=joe@perches.com \
    --cc=khali@linux-fr.org \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@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.