linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Robert Karszniewicz <avoidr@firemail.cc>,
	Rudolf Marek <r.marek@assembler.cz>,
	Jean Delvare <jdelvare@suse.com>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] hwmon: (k8temp) update to use new hwmon registration API
Date: Sat, 20 Jul 2019 14:12:08 -0700	[thread overview]
Message-ID: <325bcd3e-7795-1b34-587f-38364dd477f4@roeck-us.net> (raw)
In-Reply-To: <BVOE1YNHJDU6.38N6DGWH9KX7H@HP>

On 7/20/19 2:05 PM, Robert Karszniewicz wrote:
> Hello Guenter.
> 
> Thank you for your feedback! I am working on a version 2.
> 
> On Sat Jul 20, 2019 at 7:08 AM Guenter Roeck wrote:
>>> +static umode_t
>>> +k8temp_is_visible(const void *drvdata, enum hwmon_sensor_types type,
>>> +		  u32 attr, int channel)
>>> +{
>>> +	if (type != hwmon_temp)
>>> +		return 0;
>>
>> Not really needed since only temperature sensors are registered in the first place.
>>
>>> +
>>> +	if (attr != hwmon_temp_input)
>>> +		return 0;
>>> +
>>
>> The idea here is to only create sensors if they actually exist, so I would expect
>> something like the following here.
> 
> I realised that in the probe() function I deleted all the code which
> conditionally creates the sysfs files. Is that how it's supposed to be
> done and that's exactly what is_visible() is for, or is the proper way
> to still create the sysfs files conditionally, too?
> 

Yes, that is what the function is for. sysfs files are created in the core,
based on the result from the call to the is_visible function. If the function
returns 0, the respective sysfs file won't be created.

Thanks,
Guenter

>> 	struct k8temp_data *data = drvdata;
>>
>> 	if (attr != hwmon_temp_input)
>> 		return 0;
>>
>> 	if ((channel & 1) && !(data->sensorsp & SEL_PLACE))
>> 		return 0;
>>
>> 	if ((channel & 2) && !(data->sensorsp & SEL_CORE))
>> 		return 0;
>>
>>> +	return 0444;
>>> +}
> 
>>> +	if (data->swap_core_select)
>>> +		core = core ? 0 : 1;
>>
>> 		core = 1 - core;
>>
>> would accomplish the same without conditional.
> 
> How do you like
> 	core ^= 1;
> ?
> 
>>>    static int k8temp_probe(struct pci_dev *pdev,
>>>    				  const struct pci_device_id *id)
>>>    {
>>> -	int err;
>>>    	u8 scfg;
>>>    	u32 temp;
>>>    	u8 model, stepping;
>>>    	struct k8temp_data *data;
>>> +	struct device *hwmon_dev;
>>>    
>>>    	data = devm_kzalloc(&pdev->dev, sizeof(struct k8temp_data), GFP_KERNEL);
>>>    	if (!data)
>>> @@ -233,84 +274,23 @@ static int k8temp_probe(struct pci_dev *pdev,
>>>    
>>>    	data->name = "k8temp";
>>>    	mutex_init(&data->update_lock);
>>> -	pci_set_drvdata(pdev, data);
>>> -
>>> -	/* Register sysfs hooks */
>>> -	err = device_create_file(&pdev->dev,
>>> -			   &sensor_dev_attr_temp1_input.dev_attr);
>>> -	if (err)
>>> -		goto exit_remove;
>>> -
>>> -	/* sensor can be changed and reports something */
>>> -	if (data->sensorsp & SEL_PLACE) {
>>> -		err = device_create_file(&pdev->dev,
>>> -				   &sensor_dev_attr_temp2_input.dev_attr);
>>> -		if (err)
>>> -			goto exit_remove;
>>> -	}
>>> -
>>> -	/* core can be changed and reports something */
>>> -	if (data->sensorsp & SEL_CORE) {
>>> -		err = device_create_file(&pdev->dev,
>>> -				   &sensor_dev_attr_temp3_input.dev_attr);
>>> -		if (err)
>>> -			goto exit_remove;
>>> -		if (data->sensorsp & SEL_PLACE) {
>>> -			err = device_create_file(&pdev->dev,
>>> -					   &sensor_dev_attr_temp4_input.
>>> -					   dev_attr);
>>> -			if (err)
>>> -				goto exit_remove;
>>> -		}
>>> -	}
> 


       reply	other threads:[~2019-07-20 21:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <BVOE1YNHJDU6.38N6DGWH9KX7H@HP>
2019-07-20 21:12 ` Guenter Roeck [this message]
     [not found] <BVOE7U9MRMZY.38N6DGWH9KX7H@HP>
2019-07-20 22:46 ` [PATCH 1/2] hwmon: (k8temp) update to use new hwmon registration API Guenter Roeck
2019-07-20 13:15 [PATCH 0/2] " Robert Karszniewicz
2019-07-20 13:16 ` [PATCH 1/2] " Robert Karszniewicz
2019-07-20 14:08   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=325bcd3e-7795-1b34-587f-38364dd477f4@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=avoidr@firemail.cc \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=r.marek@assembler.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).