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

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

 



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





[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux