Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp26602680rwd; Mon, 3 Jul 2023 12:01:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlES1lm8iOEQhzHecgHjslk5ZnohNWG1xV93LcaaGbyUo8bbJKF5TQfy9svzw4aNLE60Mo1c X-Received: by 2002:a17:903:11c7:b0:1b6:6c32:59a8 with SMTP id q7-20020a17090311c700b001b66c3259a8mr10735321plh.36.1688410906654; Mon, 03 Jul 2023 12:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688410906; cv=none; d=google.com; s=arc-20160816; b=B5Tetej2hw+IkipAJbpYFmNsSFRfRpFstdCHF7VSYLR7hkiF8iAbnMxO+bvYEPVtTj 9lOB3+dtlZ5owM014yNyNP71hZMISgfcYlQB+M0gF+6kfUzR4zBiIo8G3Dams35QTUrO H8atzSl5x7Nmd3GprhbkfR447XDFrZ1Ghfm9d7g54xBRFJA0Hvz2/kKowb9VgI+XLc/N 53XYJpEg/oAHVhlWiT5HAV12HOvhIMQCUZUCRc/Fo0s1sx6eWp+b1We8ECUX/bzw6pbF orQMY2wTvgH0mN2BwYrYnqIyFtzPdWf3fKDK30sryd2GUIACT/lK0R5aEalUGC0nK/Z9 i7rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fxTO5xH6QEkUDVLzpjDkQCD7OEMcWeWP+I8hCMBouuA=; fh=5yeSY1SX/5BYKJ3zhDzboq66lb94ksAw0qpQI5n3Am0=; b=heHQ6Olk6StVLPrzDuCo6PTFMMj2hU14EYms8g/sKZhn0MiQtWHHUKSPThWQc/WUiX U35NaN308o7kqDMHsLSvU/q7D/juaPfaLRP80X9aMtLS12HCNfDj0jMQJXHNaGqNy1HZ /GTijQlNeXkOndqWF6w7Ztu57jr+MMqC1v7XS1ZaIBKhBENTBT/MUz1z/iod45RX/JkW 2R5FeIyLdN58ZUvCMZ7cCQbCDVkgDWW2JI51JBUDdTZ87X/+0Ucb2JcDIVdgJa4XJiN8 O8Cl1k0WTiCbfvyZeYe3KqXjZ4vjucMYDEsztLeL0uJ4J/j3R/je6PC6Ye61v3ir//Te 0UAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C48jagK3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a19-20020a1709027d9300b001b540c128bbsi17846735plm.308.2023.07.03.12.01.22; Mon, 03 Jul 2023 12:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=C48jagK3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231515AbjGCSww (ORCPT + 99 others); Mon, 3 Jul 2023 14:52:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231348AbjGCSwf (ORCPT ); Mon, 3 Jul 2023 14:52:35 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57407E7B; Mon, 3 Jul 2023 11:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688410353; x=1719946353; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lYPz1zqR2x3WBQCDulQo4Jbi7YfCgb1sAO+AUE8NaYA=; b=C48jagK3r8s+dfHvMr47nC+VdKWjvtdvWECCkl7yh4E/XJYG+31WGmq2 OWCpgcNwoK119LRc8oYQ40IRKCd9PK0VeszTN6f5Fs9YeUk/ALwirSI2Q o4I6ZQHDPi1Y4dqoN6pZhJkaLlWn7Nh3JrBMwGQRMvnNIyP2izpelCc8v R51KKRGqVhrnRek4vn6L9g52Wr2kv4ckZ4fP4OYkc0+uVIHwtR68yPAum MOoeNllmcqiPKBSbrF8Csnv+5+lTDsnQdjtplxaGsUlgebXosJrLK1cW2 c6IgrgZrbHw5larhIR8WOGjFdI7nyIDJDY8uq1zdzRaGe+gk1ZNsYNKPr g==; X-IronPort-AV: E=McAfee;i="6600,9927,10760"; a="449322743" X-IronPort-AV: E=Sophos;i="6.01,178,1684825200"; d="scan'208";a="449322743" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2023 11:52:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10760"; a="831912489" X-IronPort-AV: E=Sophos;i="6.01,178,1684825200"; d="scan'208";a="831912489" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 03 Jul 2023 11:52:27 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A2FA869A; Mon, 3 Jul 2023 21:52:27 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jiri Kosina , Benjamin Tissoires , Andy Shevchenko Subject: [PATCH v1 11/12] HID: cp2112: Convert to DEVICE_ATTR_RW() Date: Mon, 3 Jul 2023 21:52:21 +0300 Message-Id: <20230703185222.50554-12-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230703185222.50554-1-andriy.shevchenko@linux.intel.com> References: <20230703185222.50554-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of custom wrapper, use DEVICE_tATTR_RW() directly. Signed-off-by: Andy Shevchenko --- 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