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: <ZSzsAnE38p7zwM2+@smile.fi.intel.com>
Date:   Mon, 16 Oct 2023 10:53:38 +0300
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Angel Iglesias <ang.iglesiasg@...il.com>
Cc:     linux-iio@...r.kernel.org, Biju Das <biju.das.jz@...renesas.com>,
        linux-kernel@...r.kernel.org, Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>
Subject: Re: [PATCH 4/5] iio: pressure: bmp280: Allow multiple chips id per
 family of devices

On Sun, Oct 15, 2023 at 05:16:26PM +0200, Angel Iglesias wrote:
> Improve device detection in certain chip families known to have various
> chip ids.

...

> +#include <linux/overflow.h>

Probably you don't need this, see below.

...

>  	ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id);
>  	if (ret < 0)
>  		return ret;

> +	if (i == data->chip_info->num_chip_id) {
> +		size_t nbuf;
> +		char *buf;
> +
> +		// 0x<id>, so four chars per number plus one space + ENDL
> +		if (check_mul_overflow(data->chip_info->num_chip_id, 5, &nbuf))
> +			return ret;

First of all, it _implicitly_ returns 0 here...

> +		buf = kmalloc_array(data->chip_info->num_chip_id, 5, GFP_KERNEL);
> +		if (!buf)
> +			return ret;

...and here.

Second, kmalloc_array() has that check inside.

Third, define this magic 5 either as strlen(), or a constant (in latter case
with the comment of its meaning).

> +		for (i = 0; i < data->chip_info->num_chip_id; i++)
> +			snprintf(&buf[i*5], nbuf - i*5, "0x%x ", data->chip_info->chip_id[i]);

Fourth, use incremental position, i.e. use retuned value from snprintf().

> +		dev_err(dev, "bad chip id: expected one of [ %s ] got 0x%x\n", buf, chip_id);
> +		kfree(buf);

> +		return ret;

As per "first" and "second" above.

>  	}

-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ