linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Andy Shevchenko <andy@kernel.org>
Subject: [PATCH v1 11/12] HID: cp2112: Convert to DEVICE_ATTR_RW()
Date: Mon,  3 Jul 2023 21:52:21 +0300	[thread overview]
Message-ID: <20230703185222.50554-12-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230703185222.50554-1-andriy.shevchenko@linux.intel.com>

Instead of custom wrapper, use DEVICE_tATTR_RW() directly.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/hid/hid-cp2112.c | 42 ++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 1e45f5407d09..3c6a3be8fc02 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -944,18 +944,10 @@ CP2112_CONFIG_ATTR(release_version, ({
 
 #undef CP2112_CONFIG_ATTR
 
-struct cp2112_pstring_attribute {
-	struct device_attribute attr;
-	unsigned char report;
-};
-
-static ssize_t pstr_store(struct device *kdev,
-			  struct device_attribute *kattr, const char *buf,
-			  size_t count)
+static ssize_t pstr_store(struct device *kdev, struct device_attribute *kattr,
+			  const char *buf, size_t count, int number)
 {
 	struct hid_device *hdev = to_hid_device(kdev);
-	struct cp2112_pstring_attribute *attr =
-		container_of(kattr, struct cp2112_pstring_attribute, attr);
 	struct cp2112_string_report report;
 	int ret;
 
@@ -963,7 +955,7 @@ static ssize_t pstr_store(struct device *kdev,
 
 	ret = utf8s_to_utf16s(buf, count, UTF16_LITTLE_ENDIAN,
 			      report.string, ARRAY_SIZE(report.string));
-	report.report = attr->report;
+	report.report = number;
 	report.length = ret * sizeof(report.string[0]) + 2;
 	report.type = USB_DT_STRING;
 
@@ -981,17 +973,15 @@ static ssize_t pstr_store(struct device *kdev,
 	return count;
 }
 
-static ssize_t pstr_show(struct device *kdev,
-			 struct device_attribute *kattr, char *buf)
+static ssize_t pstr_show(struct device *kdev, struct device_attribute *kattr,
+			 char *buf, int number)
 {
 	struct hid_device *hdev = to_hid_device(kdev);
-	struct cp2112_pstring_attribute *attr =
-		container_of(kattr, struct cp2112_pstring_attribute, attr);
 	struct cp2112_string_report report;
 	u8 length;
 	int ret;
 
-	ret = cp2112_hid_get(hdev, attr->report, (u8 *)&report.contents,
+	ret = cp2112_hid_get(hdev, number, (u8 *)&report.contents,
 			     sizeof(report.contents), HID_FEATURE_REPORT);
 	if (ret < 3) {
 		hid_err(hdev, "error reading %s string: %d\n", kattr->attr.name,
@@ -1016,10 +1006,16 @@ static ssize_t pstr_show(struct device *kdev,
 }
 
 #define CP2112_PSTR_ATTR(name, _report) \
-static struct cp2112_pstring_attribute dev_attr_##name = { \
-	.attr = __ATTR(name, (S_IWUSR | S_IRUGO), pstr_show, pstr_store), \
-	.report = _report, \
-};
+static ssize_t name##_store(struct device *kdev, struct device_attribute *kattr, \
+			    const char *buf, size_t count) \
+{ \
+	return pstr_store(kdev, kattr, buf, count, _report); \
+} \
+static ssize_t name##_show(struct device *kdev, struct device_attribute *kattr, char *buf) \
+{ \
+	return pstr_show(kdev, kattr, buf, _report); \
+} \
+static DEVICE_ATTR_RW(name);
 
 CP2112_PSTR_ATTR(manufacturer,	CP2112_MANUFACTURER_STRING);
 CP2112_PSTR_ATTR(product,	CP2112_PRODUCT_STRING);
@@ -1034,9 +1030,9 @@ static const struct attribute_group cp2112_attr_group = {
 		&dev_attr_max_power.attr,
 		&dev_attr_power_mode.attr,
 		&dev_attr_release_version.attr,
-		&dev_attr_manufacturer.attr.attr,
-		&dev_attr_product.attr.attr,
-		&dev_attr_serial.attr.attr,
+		&dev_attr_manufacturer.attr,
+		&dev_attr_product.attr,
+		&dev_attr_serial.attr,
 		NULL
 	}
 };
-- 
2.40.0.1.gaa8946217a0b


  parent reply	other threads:[~2023-07-03 18:52 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-03 18:52 [PATCH v1 00/12] HID: cp2112: Cleanups and refactorings Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 01/12] lib/string_choices: Add str_write_read() helper Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 02/12] HID: cp2112: Use str_write_read() and str_read_write() Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 03/12] HID: cp2112: Make irq_chip immutable Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 04/12] HID: cp2112: Switch to for_each_set_bit() to simplify the code Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 05/12] HID: cp2112: Don't call ->to_irq() explicitly Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 06/12] HID: cp2112: Remove dead code Andy Shevchenko
2023-08-26 18:29   ` Christophe JAILLET
2023-08-28  8:52     ` Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 07/12] HID: cp2112: Define maximum GPIO constant and use it Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 08/12] HID: cp2112: Define all GPIO mask " Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 09/12] HID: cp2112: Use BIT() in GPIO setter and getter Andy Shevchenko
2023-07-03 18:52 ` [PATCH v1 10/12] HID: cp2112: Use sysfs_emit() to instead of scnprintf() Andy Shevchenko
2023-07-03 18:52 ` Andy Shevchenko [this message]
2023-07-03 18:52 ` [PATCH v1 12/12] HID: cp2112: Use octal permissions Andy Shevchenko
2023-07-27 18:43 ` [PATCH v1 00/12] HID: cp2112: Cleanups and refactorings Andy Shevchenko
2023-08-04  6:40   ` Andy Shevchenko
2023-08-07 11:19     ` Jiri Kosina
2023-08-07 14:30       ` Andy Shevchenko
2023-08-14  9:28         ` Jiri Kosina
2023-08-21  8:11           ` Andy Shevchenko
2023-08-21  8:51             ` Benjamin Tissoires
2023-08-21  9:34               ` Andy Shevchenko
2023-08-21  9:35                 ` Andy Shevchenko
2023-08-21 10:19                   ` Benjamin Tissoires
2023-08-21 10:27                     ` Benjamin Tissoires
2023-08-21 10:37                       ` Andy Shevchenko
2023-08-21 13:56                         ` Benjamin Tissoires
2023-08-21 10:32                     ` Andy Shevchenko
2023-08-21 12:06                       ` Benjamin Tissoires

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=20230703185222.50554-12-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=andy@kernel.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@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;
as well as URLs for NNTP newsgroup(s).