All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] hwmon, fam15h_power: Make actual power reporting conditional
@ 2014-09-16 15:38 Aravind Gopalakrishnan
  2014-09-16 15:52 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Aravind Gopalakrishnan @ 2014-09-16 15:38 UTC (permalink / raw)
  To: herrmann.der.user, linux, jdelvare, lm-sensors, linux-kernel
  Cc: boris.ostrovsky, Aravind Gopalakrishnan

power1_input should only be reported for Fam15h, Models 00h-0fh
So, introduce a is_visible function to take care of this.

As suggested by Guenter here:
http://marc.info/?l=linux-kernel&m=141038145616437&w=2

Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
---
 drivers/hwmon/fam15h_power.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 4a7cbfa..5ca24de 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -93,13 +93,30 @@ static ssize_t show_power_crit(struct device *dev,
 }
 static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
 
+static umode_t fam15h_power_is_visible(struct kobject *kobj,
+				       struct attribute *attr,
+				       int index)
+{
+	/* power1_input is only reported for Fam15h, Models 00h-0fh */
+	if (!strcmp(attr->name, "power1_input") &&
+	   (boot_cpu_data.x86 != 0x15 || boot_cpu_data.x86_model > 0xf)) {
+		return 0;
+	}
+
+	return attr->mode;
+}
+
 static struct attribute *fam15h_power_attrs[] = {
 	&dev_attr_power1_input.attr,
 	&dev_attr_power1_crit.attr,
 	NULL
 };
 
-ATTRIBUTE_GROUPS(fam15h_power);
+static const struct attribute_group fam15h_power_group = {
+	.attrs = fam15h_power_attrs,
+	.is_visible = fam15h_power_is_visible,
+};
+__ATTRIBUTE_GROUPS(fam15h_power);
 
 static bool fam15h_power_is_internal_node0(struct pci_dev *f4)
 {
-- 
2.0.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] hwmon, fam15h_power: Make actual power reporting conditional
  2014-09-16 15:38 [PATCH 1/2] hwmon, fam15h_power: Make actual power reporting conditional Aravind Gopalakrishnan
@ 2014-09-16 15:52 ` Guenter Roeck
  2014-09-16 15:56   ` Aravind Gopalakrishnan
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2014-09-16 15:52 UTC (permalink / raw)
  To: Aravind Gopalakrishnan
  Cc: herrmann.der.user, jdelvare, lm-sensors, linux-kernel, boris.ostrovsky

On Tue, Sep 16, 2014 at 10:38:38AM -0500, Aravind Gopalakrishnan wrote:
> power1_input should only be reported for Fam15h, Models 00h-0fh
> So, introduce a is_visible function to take care of this.
> 
> As suggested by Guenter here:
> http://marc.info/?l=linux-kernel&m=141038145616437&w=2
> 
> Suggested-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
> ---
>  drivers/hwmon/fam15h_power.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
> index 4a7cbfa..5ca24de 100644
> --- a/drivers/hwmon/fam15h_power.c
> +++ b/drivers/hwmon/fam15h_power.c
> @@ -93,13 +93,30 @@ static ssize_t show_power_crit(struct device *dev,
>  }
>  static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
>  
> +static umode_t fam15h_power_is_visible(struct kobject *kobj,
> +				       struct attribute *attr,
> +				       int index)
> +{
> +	/* power1_input is only reported for Fam15h, Models 00h-0fh */
> +	if (!strcmp(attr->name, "power1_input") &&

	if (attr == &dev_attr_power1_input.attr &&

works just as well and is simpler.

> +	   (boot_cpu_data.x86 != 0x15 || boot_cpu_data.x86_model > 0xf)) {
> +		return 0;
> +	}
> +
> +	return attr->mode;
> +}
> +
>  static struct attribute *fam15h_power_attrs[] = {
>  	&dev_attr_power1_input.attr,
>  	&dev_attr_power1_crit.attr,
>  	NULL
>  };
>  
> -ATTRIBUTE_GROUPS(fam15h_power);
> +static const struct attribute_group fam15h_power_group = {
> +	.attrs = fam15h_power_attrs,
> +	.is_visible = fam15h_power_is_visible,
> +};
> +__ATTRIBUTE_GROUPS(fam15h_power);
>  
>  static bool fam15h_power_is_internal_node0(struct pci_dev *f4)
>  {
> -- 
> 2.0.2
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] hwmon, fam15h_power: Make actual power reporting conditional
  2014-09-16 15:52 ` Guenter Roeck
@ 2014-09-16 15:56   ` Aravind Gopalakrishnan
  0 siblings, 0 replies; 3+ messages in thread
From: Aravind Gopalakrishnan @ 2014-09-16 15:56 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: herrmann.der.user, jdelvare, lm-sensors, linux-kernel, boris.ostrovsky

On 9/16/2014 10:52 AM, Guenter Roeck wrote:
> On Tue, Sep 16, 2014 at 10:38:38AM -0500, Aravind Gopalakrishnan wrote:
>> power1_input should only be reported for Fam15h, Models 00h-0fh
>> So, introduce a is_visible function to take care of this.
>>
>> As suggested by Guenter here:
>> http://marc.info/?l=linux-kernel&m=141038145616437&w=2
>>
>> Suggested-by: Guenter Roeck <linux@roeck-us.net>
>> Signed-off-by: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
>> ---
>>   drivers/hwmon/fam15h_power.c | 19 ++++++++++++++++++-
>>   1 file changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
>> index 4a7cbfa..5ca24de 100644
>> --- a/drivers/hwmon/fam15h_power.c
>> +++ b/drivers/hwmon/fam15h_power.c
>> @@ -93,13 +93,30 @@ static ssize_t show_power_crit(struct device *dev,
>>   }
>>   static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
>>   
>> +static umode_t fam15h_power_is_visible(struct kobject *kobj,
>> +				       struct attribute *attr,
>> +				       int index)
>> +{
>> +	/* power1_input is only reported for Fam15h, Models 00h-0fh */
>> +	if (!strcmp(attr->name, "power1_input") &&
> 	if (attr == &dev_attr_power1_input.attr &&
>
> works just as well and is simpler.

Ok.

>> +	   (boot_cpu_data.x86 != 0x15 || boot_cpu_data.x86_model > 0xf)) {
>> +		return 0;
>> +	}
>> +

I just noticed: I don't really need opening/closing parenthesis here. 
Shall fix and send V2.

>> +	return attr->mode;
>> +}
>> +
>>   

Thanks,
-Aravind.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-16 15:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-16 15:38 [PATCH 1/2] hwmon, fam15h_power: Make actual power reporting conditional Aravind Gopalakrishnan
2014-09-16 15:52 ` Guenter Roeck
2014-09-16 15:56   ` Aravind Gopalakrishnan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.