2020-03-15 02:25:21

by Oscar Carter

[permalink] [raw]
Subject: [PATCH] staging: vt6656: Use ARRAY_SIZE instead of hardcoded size

Use ARRAY_SIZE to replace the hardcoded size so we will never have a
mismatch.

Signed-off-by: Oscar Carter <[email protected]>
---
drivers/staging/vt6656/main_usb.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index 5e48b3ddb94c..4370941ffc04 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -23,6 +23,7 @@

#include <linux/etherdevice.h>
#include <linux/file.h>
+#include <linux/kernel.h>
#include "device.h"
#include "card.h"
#include "baseband.h"
@@ -116,6 +117,7 @@ static int vnt_init_registers(struct vnt_private *priv)
int ii;
u8 tmp;
u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
+ const int n_cck_pwr_tbl = ARRAY_SIZE(priv->cck_pwr_tbl);

dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
DEVICE_INIT_COLD, priv->packet_type);
@@ -145,7 +147,7 @@ static int vnt_init_registers(struct vnt_private *priv)

init_cmd->init_class = DEVICE_INIT_COLD;
init_cmd->exist_sw_net_addr = priv->exist_sw_net_addr;
- for (ii = 0; ii < 6; ii++)
+ for (ii = 0; ii < ARRAY_SIZE(init_cmd->sw_net_addr); ii++)
init_cmd->sw_net_addr[ii] = priv->current_net_addr[ii];
init_cmd->short_retry_limit = priv->short_retry_limit;
init_cmd->long_retry_limit = priv->long_retry_limit;
@@ -184,7 +186,7 @@ static int vnt_init_registers(struct vnt_private *priv)
priv->cck_pwr = priv->eeprom[EEP_OFS_PWR_CCK];
priv->ofdm_pwr_g = priv->eeprom[EEP_OFS_PWR_OFDMG];
/* load power table */
- for (ii = 0; ii < 14; ii++) {
+ for (ii = 0; ii < n_cck_pwr_tbl; ii++) {
priv->cck_pwr_tbl[ii] =
priv->eeprom[ii + EEP_OFS_CCK_PWR_TBL];
if (priv->cck_pwr_tbl[ii] == 0)
@@ -200,7 +202,7 @@ static int vnt_init_registers(struct vnt_private *priv)
* original zonetype is USA, but custom zonetype is Europe,
* then need to recover 12, 13, 14 channels with 11 channel
*/
- for (ii = 11; ii < 14; ii++) {
+ for (ii = 11; ii < n_cck_pwr_tbl; ii++) {
priv->cck_pwr_tbl[ii] = priv->cck_pwr_tbl[10];
priv->ofdm_pwr_tbl[ii] = priv->ofdm_pwr_tbl[10];
}
--
2.20.1


2020-03-17 10:46:09

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] staging: vt6656: Use ARRAY_SIZE instead of hardcoded size

On Sat, Mar 14, 2020 at 05:47:54PM +0100, Oscar Carter wrote:
> Use ARRAY_SIZE to replace the hardcoded size so we will never have a
> mismatch.
>
> Signed-off-by: Oscar Carter <[email protected]>
> ---
> drivers/staging/vt6656/main_usb.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
> index 5e48b3ddb94c..4370941ffc04 100644
> --- a/drivers/staging/vt6656/main_usb.c
> +++ b/drivers/staging/vt6656/main_usb.c
> @@ -23,6 +23,7 @@
>
> #include <linux/etherdevice.h>
> #include <linux/file.h>
> +#include <linux/kernel.h>
> #include "device.h"
> #include "card.h"
> #include "baseband.h"
> @@ -116,6 +117,7 @@ static int vnt_init_registers(struct vnt_private *priv)
> int ii;
> u8 tmp;
> u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
> + const int n_cck_pwr_tbl = ARRAY_SIZE(priv->cck_pwr_tbl);

Please use ARRAY_SIZE(priv->cck_pwr_tbl) everywhere instead of
introducing this new variable.

regards,
dan carpenter

2020-03-18 16:57:20

by Oscar Carter

[permalink] [raw]
Subject: Re: [PATCH] staging: vt6656: Use ARRAY_SIZE instead of hardcoded size

On Tue, Mar 17, 2020 at 01:45:06PM +0300, Dan Carpenter wrote:
> On Sat, Mar 14, 2020 at 05:47:54PM +0100, Oscar Carter wrote:
> > Use ARRAY_SIZE to replace the hardcoded size so we will never have a
> > mismatch.
> >
> > Signed-off-by: Oscar Carter <[email protected]>
> > ---
> > drivers/staging/vt6656/main_usb.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
> > index 5e48b3ddb94c..4370941ffc04 100644
> > --- a/drivers/staging/vt6656/main_usb.c
> > +++ b/drivers/staging/vt6656/main_usb.c
> > @@ -23,6 +23,7 @@
> >
> > #include <linux/etherdevice.h>
> > #include <linux/file.h>
> > +#include <linux/kernel.h>
> > #include "device.h"
> > #include "card.h"
> > #include "baseband.h"
> > @@ -116,6 +117,7 @@ static int vnt_init_registers(struct vnt_private *priv)
> > int ii;
> > u8 tmp;
> > u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
> > + const int n_cck_pwr_tbl = ARRAY_SIZE(priv->cck_pwr_tbl);
>
> Please use ARRAY_SIZE(priv->cck_pwr_tbl) everywhere instead of
> introducing this new variable.
>
Ok, I create a new version of the patch and I resend it.

> regards,
> dan carpenter
>
thanks,

oscar carter