Skip to contentSkip to conversation

platform/x86: wmi-bmof: Use device_create_bin_file()

PATCH In review Armin Wolf 2 participants 4 messages Jul 30, 2023 – Jul 31, 2023

Subsystems (2)
lore
Share & tools
lore

Armin Wolf

author maintainer
#0 lore raw

PATCH v3 1/3 platform/x86: wmi-bmof: Use device_create_bin_file()

Use device_create_bin_file() instead of sysfs_create_bin_file() to avoid having to access the device kobject.

Tested on a ASUS PRIME B650-PLUS.

---
Changes since v1:
- add Reviewed-by and Tested-by tags

---
 drivers/platform/x86/wmi-bmof.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/wmi-bmof.c +2 -2
index 80137afb9753..d0516cacfcb5 100644
@@ -75,7 +75,7 @@ static int wmi_bmof_probe(struct wmi_device *wdev, const void *context)
 	priv->bmof_bin_attr.read = read_bmof;
 	priv->bmof_bin_attr.size = priv->bmofdata->buffer.length;
 
-	ret = sysfs_create_bin_file(&wdev->dev.kobj, &priv->bmof_bin_attr);
+	ret = device_create_bin_file(&wdev->dev, &priv->bmof_bin_attr);
 	if (ret)
 		goto err_free;
 
@@ -90,7 +90,7 @@ static void wmi_bmof_remove(struct wmi_device *wdev)
 {
 	struct bmof_priv *priv = dev_get_drvdata(&wdev->dev);
 
-	sysfs_remove_bin_file(&wdev->dev.kobj, &priv->bmof_bin_attr);
+	device_remove_bin_file(&wdev->dev, &priv->bmof_bin_attr);
 	kfree(priv->bmofdata);
 }
 

--
2.39.2

author maintainer
#1 lore raw

PATCH v3 2/3 platform/x86: wmi-bmof: Simplify read_bmof()

Replace offset handling code with a single call to memory_read_from_buffer() to simplify read_bmof().

Tested on a ASUS PRIME B650-PLUS.

---
Changes since v1:
- add Reviewed-by and Tested-by tags

---
 drivers/platform/x86/wmi-bmof.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/platform/x86/wmi-bmof.c +5 -17
index d0516cacfcb5..644d2fd889c0 100644
@@ -25,25 +25,13 @@ struct bmof_priv {
 	struct bin_attribute bmof_bin_attr;
 };
 
-static ssize_t
-read_bmof(struct file *filp, struct kobject *kobj,
-	 struct bin_attribute *attr,
-	 char *buf, loff_t off, size_t count)
+static ssize_t read_bmof(struct file *filp, struct kobject *kobj, struct bin_attribute *attr,
+			 char *buf, loff_t off, size_t count)
 {
-	struct bmof_priv *priv =
-		container_of(attr, struct bmof_priv, bmof_bin_attr);
+	struct bmof_priv *priv = container_of(attr, struct bmof_priv, bmof_bin_attr);
 
-	if (off < 0)
-		return -EINVAL;
-
-	if (off >= priv->bmofdata->buffer.length)
-		return 0;
-
-	if (count > priv->bmofdata->buffer.length - off)
-		count = priv->bmofdata->buffer.length - off;
-
-	memcpy(buf, priv->bmofdata->buffer.pointer + off, count);
-	return count;
+	return memory_read_from_buffer(buf, count, &off, priv->bmofdata->buffer.pointer,
+				       priv->bmofdata->buffer.length);
 }
 
 static int wmi_bmof_probe(struct wmi_device *wdev, const void *context)

--
2.39.2

author maintainer
#2 lore raw

PATCH v3 3/3 platform/x86: wmi-bmof: Update MAINTAINERS entry

In reply to Armin Wolf

The WMI Binary MOF driver is important for the development of modern WMI drivers, i am willing to maintain it. Also fix the mailing list address.

---
Chnages since v2:
- Use correct email address
Changes since v1:
- Add Thomas Weißschuh as reviewer

---
 MAINTAINERS | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
MAINTAINERS +4 -2
index 426d3be71da2..2740849d0f87 100644
@@ -22954,8 +22954,10 @@ S:	Odd fixes
 F:	drivers/net/wireless/legacy/wl3501*
 
 WMI BINARY MOF DRIVER
-L:	[email protected]
-S:	Orphan
+M:	Armin Wolf <[email protected]>
+R:	Thomas Weißschuh <[email protected]>
+L:	[email protected]
+S:	Maintained
 F:	Documentation/ABI/stable/sysfs-platform-wmi-bmof
 F:	Documentation/wmi/devices/wmi-bmof.rst
 F:	drivers/platform/x86/wmi-bmof.c

--
2.39.2

#3 lore raw
In reply to Armin Wolf

Hi,

Quoted 8 lines · Armin Wolf

Use device_create_bin_file() instead of sysfs_create_bin_file() to avoid having to access the device kobject.

Tested on a ASUS PRIME B650-PLUS.

Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 32 lines

---
Changes since v1:
- add Reviewed-by and Tested-by tags

---
 drivers/platform/x86/wmi-bmof.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/wmi-bmof.c +2 -3
index 80137afb9753..d0516cacfcb5 100644
@@ -75,7 +75,7 @@ static int wmi_bmof_probe(struct wmi_device *wdev, const void *context)
 	priv->bmof_bin_attr.read = read_bmof;
 	priv->bmof_bin_attr.size = priv->bmofdata->buffer.length;
 
-	ret = sysfs_create_bin_file(&wdev->dev.kobj, &priv->bmof_bin_attr);
+	ret = device_create_bin_file(&wdev->dev, &priv->bmof_bin_attr);
 	if (ret)
 		goto err_free;
 
@@ -90,7 +90,7 @@ static void wmi_bmof_remove(struct wmi_device *wdev)
 {
 	struct bmof_priv *priv = dev_get_drvdata(&wdev->dev);
 
-	sysfs_remove_bin_file(&wdev->dev.kobj, &priv->bmof_bin_attr);
+	device_remove_bin_file(&wdev->dev, &priv->bmof_bin_attr);
 	kfree(priv->bmofdata);
 }
 
--

2.39.2