mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Ethan Zhao <ethan.kernel@gmail.com>
Cc: hans.verkuil@cisco.com, m.chehab@samsung.com,
	gregkh@linuxfoundation.org, mchehab@redhat.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] [media] cx18: introduce a helper function to void array overrun
Date: Sat, 4 Jan 2014 22:09:20 -0800	[thread overview]
Message-ID: <20140105060920.GE18213@core.coreip.homeip.net> (raw)
In-Reply-To: <1388884659-693-1-git-send-email-ethan.kernel@gmail.com>

Hi Ethan,

On Sun, Jan 05, 2014 at 09:17:39AM +0800, Ethan Zhao wrote:
> cx18_i2c_register() is called in cx18_init_subdevs() with index
> greater than length of hw_bus array, that will cause array overrun,
> introduce a helper cx18_get_max_bus_num() to void it.

s/void/avoid/

> 
> Signed-off-by: Ethan Zhao <ethan.kernel@gmail.com>
> ---
>  drivers/media/pci/cx18/cx18-driver.c | 2 +-
>  drivers/media/pci/cx18/cx18-i2c.c    | 5 +++++
>  drivers/media/pci/cx18/cx18-i2c.h    | 1 +
>  3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/pci/cx18/cx18-driver.c b/drivers/media/pci/cx18/cx18-driver.c
> index 6386ced..dadcd4a 100644
> --- a/drivers/media/pci/cx18/cx18-driver.c
> +++ b/drivers/media/pci/cx18/cx18-driver.c
> @@ -856,7 +856,7 @@ static void cx18_init_subdevs(struct cx18 *cx)
>  	u32 device;
>  	int i;
>  
> -	for (i = 0, device = 1; i < 32; i++, device <<= 1) {
> +	for (i = 0, device = 1; i < cx18_get_max_bus_num(); i++, device <<= 1) {
>  
>  		if (!(device & hw))
>  			continue;
> diff --git a/drivers/media/pci/cx18/cx18-i2c.c b/drivers/media/pci/cx18/cx18-i2c.c
> index 4af8cd6..e0e8193 100644
> --- a/drivers/media/pci/cx18/cx18-i2c.c
> +++ b/drivers/media/pci/cx18/cx18-i2c.c
> @@ -108,6 +108,11 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw,
>  	       -1 : 0;
>  }
>  
> +int cx18_get_max_bus_num()

This should be "int cx18_get_max_bus_num(void)" since we are using C and
not C++.

> +{
> +	return sizeof(hw_bus);

I'd rather see

	return ARRAY_SIZE(hw_bus);

Thanks.

-- 
Dmitry

  reply	other threads:[~2014-01-05  6:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-05  1:17 Ethan Zhao
2014-01-05  6:09 ` Dmitry Torokhov [this message]
2014-01-06  6:03   ` Ethan Zhao

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=20140105060920.GE18213@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=ethan.kernel@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    --cc=mchehab@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®