Re: [PATCH] e1000e: Use sizeof struct rather than pointer in e1000_get_eeprom()

From: Jeff Kirsher
Date: Mon Nov 23 2009 - 14:39:42 EST


On Sun, Nov 22, 2009 at 06:31, Roel Kluin <roel.kluin@xxxxxxxxx> wrote:
> Don't use the sizeof the pointer to clear the result
>
> Signed-off-by: Roel Kluin <roel.kluin@xxxxxxxxx>
> ---
> Âdrivers/net/e1000e/ethtool.c | Â Â3 ++-
> Â1 files changed, 2 insertions(+), 1 deletions(-)
>
>> - Â Â Â Â Â Â memset(eeprom_buff, 0xff, sizeof(eeprom_buff));
>> + Â Â Â Â Â Â memset(eeprom_buff, 0xff, sizeof(*eeprom_buff));
>
> No it's probably still not correct, eeprom_buff was kmalloc'd with:
>
> eeprom_buff = kmalloc(sizeof(u16) *
> Â Â Â Â Â Â Â Â Â Â Â Â(last_word - first_word + 1), GFP_KERNEL);
>
> How about:
>
> diff --git a/drivers/net/e1000e/ethtool.c b/drivers/net/e1000e/ethtool.c
> index 1bf4d2a..5b276c0 100644
> --- a/drivers/net/e1000e/ethtool.c
> +++ b/drivers/net/e1000e/ethtool.c
> @@ -508,7 +508,8 @@ static int e1000_get_eeprom(struct net_device *netdev,
>
> Â Â Â Âif (ret_val) {
> Â Â Â Â Â Â Â Â/* a read error occurred, throw away the result */
> - Â Â Â Â Â Â Â memset(eeprom_buff, 0xff, sizeof(eeprom_buff));
> + Â Â Â Â Â Â Â memset(eeprom_buff, 0xff, sizeof(u16) *
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (last_word - first_word + 1));
> Â Â Â Â} else {
> Â Â Â Â Â Â Â Â/* Device's eeprom is always little-endian, word addressable */
> Â Â Â Â Â Â Â Âfor (i = 0; i < last_word - first_word + 1; i++)
> --

Thanks Roel. I will add this to my tree for testing and review.

--
Cheers,
Jeff
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/