lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201119073615.GB6507@pengutronix.de>
Date:   Thu, 19 Nov 2020 08:36:15 +0100
From:   Michael Grzeschik <mgr@...gutronix.de>
To:     Andrew Lunn <andrew@...n.ch>
Cc:     netdev@...r.kernel.org, f.fainelli@...il.com, davem@...emloft.net,
        kernel@...gutronix.de, matthias.schiffer@...tq-group.com,
        woojung.huh@...rochip.com, UNGLinuxDriver@...rochip.com
Subject: Re: [PATCH 05/11] net: dsa: microchip: ksz8795: use mib_cnt where
 possible

Hi Andrew!

On Thu, Nov 19, 2020 at 01:20:47AM +0100, Andrew Lunn wrote:
>On Wed, Nov 18, 2020 at 11:03:51PM +0100, Michael Grzeschik wrote:
>> The variable mib_cnt is assigned with TOTAL_SWITCH_COUNTER_NUM. This
>> value can also be derived from the array size of mib_names. This patch
>> uses this calculated value instead, removes the extra define and uses
>> mib_cnt everywhere possible instead of the static define
>> TOTAL_SWITCH_COUNTER_NUM.
>>
>> Signed-off-by: Michael Grzeschik <m.grzeschik@...gutronix.de>
>> ---
>>  drivers/net/dsa/microchip/ksz8795.c     | 8 ++++----
>>  drivers/net/dsa/microchip/ksz8795_reg.h | 3 ---
>>  2 files changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
>> index 04a571bde7e6a4f..6ddba2de2d3026e 100644
>> --- a/drivers/net/dsa/microchip/ksz8795.c
>> +++ b/drivers/net/dsa/microchip/ksz8795.c
>> @@ -23,7 +23,7 @@
>>
>>  static const struct {
>>  	char string[ETH_GSTRING_LEN];
>> -} mib_names[TOTAL_SWITCH_COUNTER_NUM] = {
>> +} mib_names[] = {
>>  	{ "rx_hi" },
>>  	{ "rx_undersize" },
>>  	{ "rx_fragments" },
>> @@ -656,7 +656,7 @@ static void ksz8795_get_strings(struct dsa_switch *ds, int port,
>>  {
>>  	int i;
>>
>> -	for (i = 0; i < TOTAL_SWITCH_COUNTER_NUM; i++) {
>> +	for (i = 0; i < dev->mib_cnt; i++) {
>>  		memcpy(buf + i * ETH_GSTRING_LEN, mib_names[i].string,
>>  		       ETH_GSTRING_LEN);
>>  	}
>> @@ -1236,7 +1236,7 @@ static int ksz8795_switch_init(struct ksz_device *dev)
>>  	dev->port_mask |= dev->host_mask;
>>
>>  	dev->reg_mib_cnt = KSZ8795_COUNTER_NUM;
>> -	dev->mib_cnt = TOTAL_SWITCH_COUNTER_NUM;
>> +	dev->mib_cnt = ARRAY_SIZE(mib_names);
>
>Hi Michael
>
>I think it would be better to just use ARRAY_SIZE(mib_names)
>everywhere. It is one less hoop to jump through when looking for array
>overruns, etc.

I would better stay with the variable, because of two reasons. First it
is also used in ksz_common.c and ksz_9477.c. Also in my next patches
I will introduce another mib_names array. We will have ksz8863_mib_names
and ksz8795_mib_names. In the init function then the mib_cnt will be set
regarding to the chip that is found.

Do you agree that the extra variable makes the code more readable in
that case?

Regards,
Michael

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ