2011-02-22 08:56:54

by Eibach, Dirk

[permalink] [raw]
Subject: [PATCH] gpio: Fix wrong pointer type in pca953x

pca953x_get_alt_pdata() uses uint16_t* as result type for
of_get_property(), but numeric of values are u32.

Signed-off-by: Dirk Eibach <[email protected]>
---
drivers/gpio/pca953x.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index a261972..d79e031 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -448,7 +448,7 @@ pca953x_get_alt_pdata(struct i2c_client *client)
{
struct pca953x_platform_data *pdata;
struct device_node *node;
- const uint16_t *val;
+ const u32 *val;

node = client->dev.of_node;
if (node == NULL)
--
1.5.6.5


2011-02-22 12:39:57

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] gpio: Fix wrong pointer type in pca953x

On Tue, Feb 22, 2011 at 09:56:50AM +0100, Dirk Eibach wrote:
> struct pca953x_platform_data *pdata;
> struct device_node *node;
> - const uint16_t *val;
> + const u32 *val;
>

This should probably be signed? We compare it against zero later on.

if (*val < 0)
dev_warn(&client->dev,
"invalid gpio-base in device tree\n");

regards,
dan carpenter

2011-02-22 12:54:22

by Eibach, Dirk

[permalink] [raw]
Subject: RE: [PATCH] gpio: Fix wrong pointer type in pca953x



> > struct pca953x_platform_data *pdata;
> > struct device_node *node;
> > - const uint16_t *val;
> > + const u32 *val;
> >
>
> This should probably be signed? We compare it against zero later on.
>
> if (*val < 0)
> dev_warn(&client->dev,
> "invalid gpio-base in device
> tree\n");

Good catch.
of property values are generally unsigned. The whole check is bogus
here. Will supply updated patch later.

> regards,
> dan carpenter

Cheers
Dirk

2011-02-22 13:28:09

by Eibach, Dirk

[permalink] [raw]
Subject: [PATCH v2] gpio: Fix wrong pointer type in pca953x

pca953x_get_alt_pdata() uses uint16_t* as result type for
of_get_property(), but numeric of values are u32.

Checking for negative values is bogus because of-property
values are unsigned by definition.

Signed-off-by: Dirk Eibach <[email protected]>
---
Changes since v1:
- removed bogus check for negative property values

drivers/gpio/pca953x.c | 11 +++--------
1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index a261972..8acbfe9 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -448,7 +448,7 @@ pca953x_get_alt_pdata(struct i2c_client *client)
{
struct pca953x_platform_data *pdata;
struct device_node *node;
- const uint16_t *val;
+ const u32 *val;

node = client->dev.of_node;
if (node == NULL)
@@ -462,13 +462,8 @@ pca953x_get_alt_pdata(struct i2c_client *client)

pdata->gpio_base = -1;
val = of_get_property(node, "linux,gpio-base", NULL);
- if (val) {
- if (*val < 0)
- dev_warn(&client->dev,
- "invalid gpio-base in device tree\n");
- else
- pdata->gpio_base = *val;
- }
+ if (val)
+ pdata->gpio_base = *val;

val = of_get_property(node, "polarity", NULL);
if (val)
--
1.5.6.5

2011-02-24 09:20:51

by Eibach, Dirk

[permalink] [raw]
Subject: [PATCH v3] gpio: Fix wrong pointer type in pca953x

pca953x_get_alt_pdata() uses uint16_t* as result type for
of_get_property(), but numeric of values are __be32.

Checking for negative values is bogus because of-property
values are unsigned by definition.
Instead check for proper property size.

Signed-off-by: Dirk Eibach <[email protected]>
---
Changes since v1:
- removed bogus check for negative property values

Changes since v2:
- assume big-endian properties
- check property size

drivers/gpio/pca953x.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index a261972..694b0f9 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -448,7 +448,8 @@ pca953x_get_alt_pdata(struct i2c_client *client)
{
struct pca953x_platform_data *pdata;
struct device_node *node;
- const uint16_t *val;
+ const __be32 *val;
+ int size;

node = client->dev.of_node;
if (node == NULL)
@@ -461,13 +462,13 @@ pca953x_get_alt_pdata(struct i2c_client *client)
}

pdata->gpio_base = -1;
- val = of_get_property(node, "linux,gpio-base", NULL);
+ val = of_get_property(node, "linux,gpio-base", &size);
if (val) {
- if (*val < 0)
- dev_warn(&client->dev,
- "invalid gpio-base in device tree\n");
+ if (size != sizeof(*val))
+ dev_warn(&client->dev, "%s: wrong linux,gpio-base\n",
+ node->full_name);
else
- pdata->gpio_base = *val;
+ pdata->gpio_base = be32_to_cpup(val);
}

val = of_get_property(node, "polarity", NULL);
--
1.5.6.5

2011-02-24 15:56:17

by Grant Likely

[permalink] [raw]
Subject: Re: [PATCH v3] gpio: Fix wrong pointer type in pca953x

On Thu, Feb 24, 2011 at 10:20:43AM +0100, Dirk Eibach wrote:
> pca953x_get_alt_pdata() uses uint16_t* as result type for
> of_get_property(), but numeric of values are __be32.
>
> Checking for negative values is bogus because of-property
> values are unsigned by definition.
> Instead check for proper property size.
>
> Signed-off-by: Dirk Eibach <[email protected]>

Applied, thanks.

g.