Re: [PATCH v2 2/2] hwmon: sht3x: read out sensor serial number

From: Guenter Roeck
Date: Mon Dec 11 2023 - 10:28:25 EST


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