Skip to contentSkip to conversation

staging: fbtft: check return value of device_create_file()

PATCH In review Harshit Shaw 3 participants 3 messages May 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fbtft: check return value of device_create_file()

device_create_file() can fail but its return value was being ignored in fbtft_sysfs_init(). Check the return value and emit a warning if sysfs file creation fails.

---
 drivers/staging/fbtft/fbtft-sysfs.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/staging/fbtft/fbtft-sysfs.c +10 -3
index d05599d80011..cc6dbaeb6043 100644
@@ -204,14 +204,21 @@ static struct device_attribute debug_device_attr =
 void fbtft_sysfs_init(struct fbtft_par *par)
 {
 	struct device *dev;
+	int ret;
 
 	dev = dev_of_fbinfo(par->info);
 	if (!dev)
 		return;
 
-	device_create_file(dev, &debug_device_attr);
-	if (par->gamma.curves && par->fbtftops.set_gamma)
-		device_create_file(dev, &gamma_device_attrs[0]);
+	ret = device_create_file(dev, &debug_device_attr);
+	if (ret)
+		dev_warn(dev, "failed to create debug sysfs entry\n");
+
+	if (par->gamma.curves && par->fbtftops.set_gamma) {
+		ret = device_create_file(dev, &gamma_device_attrs[0]);
+		if (ret)
+			dev_warn(dev, "failed to create gamma sysfs entry\n");
+	}
 }
 
 void fbtft_sysfs_exit(struct fbtft_par *par)
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 19 lines · Harshit Shaw

device_create_file() can fail but its return value was being ignored in fbtft_sysfs_init(). Check the return value and emit a warning if sysfs file creation fails.

---
 drivers/staging/fbtft/fbtft-sysfs.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/staging/fbtft/fbtft-sysfs.c +1 -0
index d05599d80011..cc6dbaeb6043 100644
@@ -204,14 +204,21 @@ static struct device_attribute debug_device_attr =
 void fbtft_sysfs_init(struct fbtft_par *par)
 {
 	struct device *dev;
+	int ret;
 

drivers/staging/fbtft/fbtft-sysfs.c static struct device_attribute debug_device_attr = · line 215

Quoted 10 lines
drivers/staging/fbtft/fbtft-sysfs.c +3 -3
 	dev = dev_of_fbinfo(par->info);
 	if (!dev)
 		return;
 
-	device_create_file(dev, &debug_device_attr);
-	if (par->gamma.curves && par->fbtftops.set_gamma)
-		device_create_file(dev, &gamma_device_attrs[0]);
+	ret = device_create_file(dev, &debug_device_attr);
+	if (ret)
+		dev_warn(dev, "failed to create debug sysfs entry\n");

This sysfs file should not be there at all, can you work to remove it and just use the "normal" debug api for logging stuff?

Also, no driver should be calling this function directly, a default attribute group is the correct solution. So don't paper over this warning by just checking the error value now, do the right thing instead.

thanks,

greg k-h

#2 lore raw
In reply to Harshit Shaw
Quoted 6 lines · Harshit Shaw

device_create_file() can fail but its return value was being ignored in fbtft_sysfs_init(). Check the return value and emit a warning if sysfs file creation fails.

---

What's the point of this though? How is your warning message more informative than the warning messages printed out by device_create_file()?

regards,
dan carpenter