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: <ZN9TyGjr/pqLQUpT@smile.fi.intel.com>
Date:   Fri, 18 Aug 2023 14:19:36 +0300
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Angel Iglesias <ang.iglesiasg@...il.com>
Cc:     linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
        Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>
Subject: Re: [PATCH 1/2] iio: pressure: bmp280: Allow multiple chips id per
 family of devices

On Thu, Aug 17, 2023 at 11:05:21PM +0200, Angel Iglesias wrote:
> Improve device detection in certain chip families known to have various
> chip ids.

...

> +	ret = -EINVAL;

Why do you need this...

> +	for (i = 0; i < data->chip_info->num_chip_id; i++) {
> +		if (chip_id == data->chip_info->chip_id[i]) {

> +			ret = 0;

..and this...

> +			break;
> +		}
> +	}

> +	if (ret) {

...and this?

You can simply do

	for (i = 0; i < data->chip_info->num_chip_id; i++) {
		if (chip_id == data->chip_info->chip_id[i])
			break;
	}
	if (i < data->chip_info->num_chip_id) {

...

> +		// 0x<id>, so four chars per number plus one space + ENDL
> +		size_t nbuf = 5*data->chip_info->num_chip_id*sizeof(char);

Besides lack of spaces...

> +		char *buf = kmalloc(nbuf, GFP_KERNEL);

...this at least should be kmalloc_array() and on top maybe something from
overflow.h will be needed.

> +		if (!buf)
> +			return ret;
> +
> +		for (i = 0; i < data->chip_info->num_chip_id; i++)
> +			snprintf(&buf[i*5], nbuf, "0x%x ", data->chip_info->chip_id[i]);
> +		buf[nbuf-1] = '\0';
> +
> +		dev_err(dev, "bad chip id: expected [ %s ] got 0x%x\n", buf, chip_id);
> +		kfree(buf);
> +		return ret;
>  	}

...

> -	const unsigned int chip_id;

Yeah, this const makes a little sense...

> +	const unsigned int *chip_id;

...but not this :-)

What I'm wondering is why it's int and not u8 / u16
(as it seems only a byte value there).

> +	int num_chip_id;

unsigned.

-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ