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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Sat, 1 Dec 2018 10:40:34 -0800
From:   Guenter Roeck <linux@...ck-us.net>
To:     Peter Rosin <peda@...ntia.se>
Cc:     "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        Jean Delvare <jdelvare@...e.com>,
        "linux-hwmon@...r.kernel.org" <linux-hwmon@...r.kernel.org>
Subject: Re: [PATCH 2/2] hwmon: (ntc_thermistor) use a table to lookup the
 thermistor type

On Wed, Nov 21, 2018 at 04:03:46PM +0000, Peter Rosin wrote:
> Sort the entries while at it.
> 
> Signed-off-by: Peter Rosin <peda@...ntia.se>

Applied to hwmon-next.

Thanks,
Guenter

> ---
>  drivers/hwmon/ntc_thermistor.c               | 47 +++++++++++++---------------
>  include/linux/platform_data/ntc_thermistor.h |  6 ++--
>  2 files changed, 24 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
> index 7747c1ed1f02..56d83b2472c8 100644
> --- a/drivers/hwmon/ntc_thermistor.c
> +++ b/drivers/hwmon/ntc_thermistor.c
> @@ -315,6 +315,23 @@ static const struct ntc_compensation b57891s0103[] = {
>  	{ .temp_c	= 155.0, .ohm	= 168 },
>  };
>  
> +struct ntc_type {
> +	const struct ntc_compensation *comp;
> +	int n_comp;
> +};
> +
> +#define NTC_TYPE(ntc, compensation) \
> +[(ntc)] = { .comp = (compensation), .n_comp = ARRAY_SIZE(compensation) }
> +
> +static const struct ntc_type ntc_type[] = {
> +	NTC_TYPE(TYPE_B57330V2103, b57330v2103),
> +	NTC_TYPE(TYPE_B57891S0103, b57891s0103),
> +	NTC_TYPE(TYPE_NCPXXWB473,  ncpXXwb473),
> +	NTC_TYPE(TYPE_NCPXXWF104,  ncpXXwf104),
> +	NTC_TYPE(TYPE_NCPXXWL333,  ncpXXwl333),
> +	NTC_TYPE(TYPE_NCPXXXH103,  ncpXXxh103),
> +};
> +
>  struct ntc_data {
>  	struct ntc_thermistor_platform_data *pdata;
>  	const struct ntc_compensation *comp;
> @@ -671,37 +688,15 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
>  
>  	data->pdata = pdata;
>  
> -	switch (pdev_id->driver_data) {
> -	case TYPE_NCPXXWB473:
> -		data->comp = ncpXXwb473;
> -		data->n_comp = ARRAY_SIZE(ncpXXwb473);
> -		break;
> -	case TYPE_NCPXXWL333:
> -		data->comp = ncpXXwl333;
> -		data->n_comp = ARRAY_SIZE(ncpXXwl333);
> -		break;
> -	case TYPE_B57330V2103:
> -		data->comp = b57330v2103;
> -		data->n_comp = ARRAY_SIZE(b57330v2103);
> -		break;
> -	case TYPE_NCPXXWF104:
> -		data->comp = ncpXXwf104;
> -		data->n_comp = ARRAY_SIZE(ncpXXwf104);
> -		break;
> -	case TYPE_NCPXXXH103:
> -		data->comp = ncpXXxh103;
> -		data->n_comp = ARRAY_SIZE(ncpXXxh103);
> -		break;
> -	case TYPE_B57891S0103:
> -		data->comp = b57891s0103;
> -		data->n_comp = ARRAY_SIZE(b57891s0103);
> -		break;
> -	default:
> +	if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) {
>  		dev_err(dev, "Unknown device type: %lu(%s)\n",
>  				pdev_id->driver_data, pdev_id->name);
>  		return -EINVAL;
>  	}
>  
> +	data->comp   = ntc_type[pdev_id->driver_data].comp;
> +	data->n_comp = ntc_type[pdev_id->driver_data].n_comp;
> +
>  	hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name,
>  							   data, ntc_groups);
>  	if (IS_ERR(hwmon_dev)) {
> diff --git a/include/linux/platform_data/ntc_thermistor.h b/include/linux/platform_data/ntc_thermistor.h
> index 231a27c302ec..ee03d429742b 100644
> --- a/include/linux/platform_data/ntc_thermistor.h
> +++ b/include/linux/platform_data/ntc_thermistor.h
> @@ -24,12 +24,12 @@
>  struct iio_channel;
>  
>  enum ntc_thermistor_type {
> -	TYPE_NCPXXWB473,
> -	TYPE_NCPXXWL333,
>  	TYPE_B57330V2103,
> +	TYPE_B57891S0103,
> +	TYPE_NCPXXWB473,
>  	TYPE_NCPXXWF104,
> +	TYPE_NCPXXWL333,
>  	TYPE_NCPXXXH103,
> -	TYPE_B57891S0103,
>  };
>  
>  struct ntc_thermistor_platform_data {

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ