* [PATCH] [media] cx18: introduce a helper function to void array overrun
@ 2014-01-05 1:17 Ethan Zhao
2014-01-05 6:09 ` Dmitry Torokhov
0 siblings, 1 reply; 3+ messages in thread
From: Ethan Zhao @ 2014-01-05 1:17 UTC (permalink / raw)
To: hans.verkuil, m.chehab, gregkh, mchehab; +Cc: linux-kernel, Ethan Zhao
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.
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()
+{
+ return sizeof(hw_bus);
+}
+
int cx18_i2c_register(struct cx18 *cx, unsigned idx)
{
struct v4l2_subdev *sd;
diff --git a/drivers/media/pci/cx18/cx18-i2c.h b/drivers/media/pci/cx18/cx18-i2c.h
index 1180fdc..8cce205 100644
--- a/drivers/media/pci/cx18/cx18-i2c.h
+++ b/drivers/media/pci/cx18/cx18-i2c.h
@@ -21,6 +21,7 @@
* 02111-1307 USA
*/
+int cx18_get_max_bus_num();
int cx18_i2c_register(struct cx18 *cx, unsigned idx);
struct v4l2_subdev *cx18_find_hw(struct cx18 *cx, u32 hw);
--
1.8.3.4 (Apple Git-47)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] [media] cx18: introduce a helper function to void array overrun
2014-01-05 1:17 [PATCH] [media] cx18: introduce a helper function to void array overrun Ethan Zhao
@ 2014-01-05 6:09 ` Dmitry Torokhov
2014-01-06 6:03 ` Ethan Zhao
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2014-01-05 6:09 UTC (permalink / raw)
To: Ethan Zhao; +Cc: hans.verkuil, m.chehab, gregkh, mchehab, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] [media] cx18: introduce a helper function to void array overrun
2014-01-05 6:09 ` Dmitry Torokhov
@ 2014-01-06 6:03 ` Ethan Zhao
0 siblings, 0 replies; 3+ messages in thread
From: Ethan Zhao @ 2014-01-06 6:03 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: hans.verkuil, m.chehab, Greg KH, mchehab, LKML
On Sun, Jan 5, 2014 at 2:09 PM, Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
> 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/
Oops, typo.
>
>>
>> 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++.
agree, no parameter function, f(void) much clearer than any parameters
function f() in C.
>
>> +{
>> + return sizeof(hw_bus);
>
> I'd rather see
>
> return ARRAY_SIZE(hw_bus);
Yes, looks better ! will send v2, thanks.
>
> Thanks.
>
> --
> Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-06 6:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-05 1:17 [PATCH] [media] cx18: introduce a helper function to void array overrun Ethan Zhao
2014-01-05 6:09 ` Dmitry Torokhov
2014-01-06 6:03 ` Ethan Zhao
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.