2008-04-23 19:56:52

by Roel Kluin

[permalink] [raw]
Subject: [PATCH] prism54: prism54_get_encode() test below 0 on unsigned index

previously in this function:

u32 index = (dwrq->flags & IW_ENCODE_INDEX) - 1;

index is unsigned, so if -1, the original test (below) didn't work.

Signed-off-by: Roel Kluin <[email protected]>
---
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index e5b3c28..5b375b2 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -1186,7 +1186,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
devindex = r.u;
/* Now get the key, return it */
- if ((index < 0) || (index > 3))
+ if (index == -1 || index > 3)
/* no index provided, use the current one */
index = devindex;
rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);


2008-04-26 04:39:27

by Luis R. Rodriguez

[permalink] [raw]
Subject: Re: [PATCH v2] prism54: prism54_get_encode() test below 0 on unsigned index

On Fri, Apr 25, 2008 at 02:45:14AM +0200, Roel Kluin wrote:
> Dan Williams wrote:
> > On Wed, 2008-04-23 at 21:56 +0200, Roel Kluin wrote:
>
> >> u32 index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
> >
> > Probably should just change that to an 'int' instead of a u32.
> >
> > Dan
> >
>
> Thanks, in that case use the patch below
> ---
> when left unsigned, the test 'if (index < 0)' will not work.
>
> Signed-off-by: Roel Kluin <[email protected]>
> ---
> diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
> index e5b3c28..8076ead 100644
> --- a/drivers/net/wireless/prism54/isl_ioctl.c
> +++ b/drivers/net/wireless/prism54/isl_ioctl.c
> @@ -1158,7 +1158,8 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
> {
> islpci_private *priv = netdev_priv(ndev);
> struct obj_key *key;
> - u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
> + u32 devindex;
> + int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;

The check for -1 seems silly lets just remove its use.

Signed-off-by: Luis R. Rodriguez <[email protected]>

diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index 5b375b2..7e2d3b6 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -1158,7 +1158,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
{
islpci_private *priv = netdev_priv(ndev);
struct obj_key *key;
- u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+ u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX);
u32 authen = 0, invoke = 0, exunencrypt = 0;
int rvalue;
union oid_res_t r;
@@ -1186,7 +1186,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
devindex = r.u;
/* Now get the key, return it */
- if (index == -1 || index > 3)
+ if (!index || index > 3)
/* no index provided, use the current one */
index = devindex;
rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);

2008-04-24 17:13:19

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH] prism54: prism54_get_encode() test below 0 on unsigned index

On Wed, 2008-04-23 at 21:56 +0200, Roel Kluin wrote:
> previously in this function:
>
> u32 index = (dwrq->flags & IW_ENCODE_INDEX) - 1;

Probably should just change that to an 'int' instead of a u32.

Dan

> index is unsigned, so if -1, the original test (below) didn't work.
>
> Signed-off-by: Roel Kluin <[email protected]>
> ---
> diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
> index e5b3c28..5b375b2 100644
> --- a/drivers/net/wireless/prism54/isl_ioctl.c
> +++ b/drivers/net/wireless/prism54/isl_ioctl.c
> @@ -1186,7 +1186,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
> rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
> devindex = r.u;
> /* Now get the key, return it */
> - if ((index < 0) || (index > 3))
> + if (index == -1 || index > 3)
> /* no index provided, use the current one */
> index = devindex;
> rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html


2008-04-28 04:13:59

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH v2] prism54: prism54_get_encode() test below 0 on unsigned index

On Sat, 2008-04-26 at 00:39 -0400, Luis R. Rodriguez wrote:
> On Fri, Apr 25, 2008 at 02:45:14AM +0200, Roel Kluin wrote:
> > Dan Williams wrote:
> > > On Wed, 2008-04-23 at 21:56 +0200, Roel Kluin wrote:
> >
> > >> u32 index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
> > >
> > > Probably should just change that to an 'int' instead of a u32.
> > >
> > > Dan
> > >
> >
> > Thanks, in that case use the patch below
> > ---
> > when left unsigned, the test 'if (index < 0)' will not work.
> >
> > Signed-off-by: Roel Kluin <[email protected]>
> > ---
> > diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
> > index e5b3c28..8076ead 100644
> > --- a/drivers/net/wireless/prism54/isl_ioctl.c
> > +++ b/drivers/net/wireless/prism54/isl_ioctl.c
> > @@ -1158,7 +1158,8 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
> > {
> > islpci_private *priv = netdev_priv(ndev);
> > struct obj_key *key;
> > - u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
> > + u32 devindex;
> > + int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
>
> The check for -1 seems silly lets just remove its use.
>
> Signed-off-by: Luis R. Rodriguez <[email protected]>
>
> diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
> index 5b375b2..7e2d3b6 100644
> --- a/drivers/net/wireless/prism54/isl_ioctl.c
> +++ b/drivers/net/wireless/prism54/isl_ioctl.c
> @@ -1158,7 +1158,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
> {
> islpci_private *priv = netdev_priv(ndev);
> struct obj_key *key;
> - u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
> + u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX);
> u32 authen = 0, invoke = 0, exunencrypt = 0;
> int rvalue;
> union oid_res_t r;
> @@ -1186,7 +1186,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
> rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
> devindex = r.u;
> /* Now get the key, return it */
> - if (index == -1 || index > 3)
> + if (!index || index > 3)
> /* no index provided, use the current one */
> index = devindex;
> rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);

This won't allow you to select index 0 then. Hence the reason why the
-1 is necessary, so you can distinguish 'no index specified' from 'use
index 0'. There's probably a better way to do it, but I don't think
this patch will work.

Dan



2008-04-25 00:46:15

by Roel Kluin

[permalink] [raw]
Subject: [PATCH v2] prism54: prism54_get_encode() test below 0 on unsigned index

Dan Williams wrote:
> On Wed, 2008-04-23 at 21:56 +0200, Roel Kluin wrote:

>> u32 index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
>
> Probably should just change that to an 'int' instead of a u32.
>
> Dan
>

Thanks, in that case use the patch below
---
when left unsigned, the test 'if (index < 0)' will not work.

Signed-off-by: Roel Kluin <[email protected]>
---
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index e5b3c28..8076ead 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -1158,7 +1158,8 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
{
islpci_private *priv = netdev_priv(ndev);
struct obj_key *key;
- u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+ u32 devindex;
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
u32 authen = 0, invoke = 0, exunencrypt = 0;
int rvalue;
union oid_res_t r;