public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Stefan Gloor <code@stefan-gloor.ch>
Cc: jdelvare@suse.com, corbet@lwn.net, linux-hwmon@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] hwmon: sht3x: read out sensor serial number
Date: Mon, 11 Dec 2023 07:28:18 -0800	[thread overview]
Message-ID: <37fc9395-1ef4-4e79-af4e-5d8b9090ec99@roeck-us.net> (raw)
In-Reply-To: <20231211151216.yehwa27daveq57jo@thinkpad>

On 12/11/23 07:12, Stefan Gloor wrote:
> On Mon, Dec 11, 2023 at 06:31:27AM -0800, Guenter Roeck wrote:
>> On Mon, Dec 04, 2023 at 05:50:04PM +0100, Stefan Gloor wrote:
>>>   
>>> +#ifdef CONFIG_DEBUG_FS
>>> +
>>> +static void sht3x_debugfs_init(struct sht3x_data *data)
>>> +{
>>> +	char name[32];
>>> +	struct dentry *sensor_dir;
>>> +
>>> +	data->debugfs = debugfs_lookup("sht3x", NULL);
>>> +	if (IS_ERR_OR_NULL(data->debugfs))
>>> +		data->debugfs = debugfs_create_dir("sht3x", NULL);
>>> +
>>> +	snprintf(name, sizeof(name), "i2c%u-%02x",
>>> +		 data->client->adapter->nr, data->client->addr);
>>> +	sensor_dir = debugfs_create_dir(name, data->debugfs);
>>> +	debugfs_create_u32("serial_number", 0444,
>>> +			   sensor_dir, &data->serial_number);
>>> +}
>>> +
>>> +#else
>>> +
>>> +static void sht3x_debugfs_init(struct sht3x_data *data)
>>> +{
>>> +}
>>> +
>>> +#endif
>>
>> debugfs doesn't need if/else or error handling.
>>
> Do you mean the IS_ERR_OR_NULL? I included that to get rid of the
> "debugfs directory already exists" message when using multiple sensors.
> 

A much easier way to do that would be to create the directory in the init function,
and to use a static variable to point to it. Note that you'll also need need an
explicit exit function to remove it when the driver is unloaded.

Thanks,
Guenter


      reply	other threads:[~2023-12-11 15:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 16:50 [PATCH v2 0/2] hwmon: sht3x: improve docs, read serial number Stefan Gloor
2023-12-04 16:50 ` [PATCH v2 1/2] hwmon: sht3x: add sts3x support Stefan Gloor
2023-12-11 14:28   ` Guenter Roeck
2023-12-04 16:50 ` [PATCH v2 2/2] hwmon: sht3x: read out sensor serial number Stefan Gloor
2023-12-11 14:31   ` Guenter Roeck
2023-12-11 15:12     ` Stefan Gloor
2023-12-11 15:28       ` Guenter Roeck [this message]

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=37fc9395-1ef4-4e79-af4e-5d8b9090ec99@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=code@stefan-gloor.ch \
    --cc=corbet@lwn.net \
    --cc=jdelvare@suse.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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