Re: [PATCH] intel_menlow: reduce code duplication

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2016-03-26 at 22:40 +0100, Rasmus Villemoes wrote:
> aux0_show and aux1_show consists of almost identical code. Pull that
> into a common helper and make them thin wrappers. Similarly for
> _store.

Seems sensible, thanks

> diff --git a/drivers/platform/x86/intel_menlow.c b/drivers/platform/x86/intel_menlow.c
[]
> @@ -306,33 +306,32 @@ static int sensor_set_auxtrip(acpi_handle handle, int index, int value)
>  #define to_intel_menlow_attr(_attr)	\
>  	container_of(_attr, struct intel_menlow_attribute, attr)
>  
> -static ssize_t aux0_show(struct device *dev,
> -			 struct device_attribute *dev_attr, char *buf)
> +static ssize_t aux_show(struct device *dev, struct device_attribute *dev_attr,
> +			char *buf, int idx)
>  {
>  	struct intel_menlow_attribute *attr = to_intel_menlow_attr(dev_attr);
>  	unsigned long long value;
>  	int result;
>  
> -	result = sensor_get_auxtrip(attr->handle, 0, &value);
> +	result = sensor_get_auxtrip(attr->handle, idx, &value);
>  
>  	return result ? result : sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value));

While not something you've done differently than the
existing code, perhaps this would be more common
without the ternary operator like:

	result = sensor_get_auxtrip(attr->handle, idx, &value);
	if (result < 0)
		return result;

	return sprintf(buf, "%lu", DECI_KELVIN_TO_CELSIUS(value));

--
To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux