Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1393552lqt; Sat, 20 Apr 2024 13:07:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9eNChQ9KaOoxKiAfgq65SQVd12dBagLrZrJXoDbYg4eGpo3nJfUA5PjxN/nF5Hv/kPrZOuRuKx0UfoP8mFkkLqJfmKp3o/p3X3lmW0w== X-Google-Smtp-Source: AGHT+IF5bcRSU0fs9+xP2xLI7kWtviJwgxI1Uo9bGZiVAc+6zoWmcXsBknFd5U6bNyBO15Ns6S55 X-Received: by 2002:a05:6a21:6d85:b0:1ac:dead:b221 with SMTP id wl5-20020a056a216d8500b001acdeadb221mr3473792pzb.40.1713643665013; Sat, 20 Apr 2024 13:07:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713643664; cv=pass; d=google.com; s=arc-20160816; b=rYIsD1FXE94UiFW0CZxJNqvcyTHqW7w8b7sdIK4XL8hFI5yS6NZt5rLSg00FPSrkBj 52hVTx85CK80B7IFaozPYR+dJ7m7HIcZVzCiKbx1K5KXub9rI98n3FyTlWmvH6OU2Q93 LjlXthC5itp0wL5sWD6oVsvOgohPJ8TurqIT2YIxasJY6qRkNloqcO4EMWdxg1dwOv5r 0kEiy5ga/pe81nqKi7HGPy6NBSuXU21J1o8mqdayRKB9w8DFI/eTFqy0+n38OunXicQr cwTgSBi5i0pq2HCifLIitTMkw62ekKqN/Y2thP9C7hwAzqMEUtHQX4uUtjGcbjxHXLtv C5hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:cc:to:subject :date:from:references:in-reply-to:message-id; bh=WiywwQ6yy3xuJsYi1zDCYy8DJdimyKKvCTHkc1QnJLg=; fh=GIUevHaGIpSDliFvZ5LkgGQWzB2bdpZHOx8CeXznltw=; b=r1mUMla8t6utDGTk79hsci4C0r20uVW/kE8Yz2wISn9cUiPmk5MFJX3kwxZ7FaLxwi C1wfAkepUeM1O6fLwd0x/xx6m10fmgXY4o1gp0P205jhgwc8GJ1dkM3XM9MxLcES1Piz b7loinGwr1RMG4miw2wzEYuKF3PZMZ8ML4DVkwNyCbrib1mtlIUpvCBU4qe2zo44j8wk sLXDpTpaMRiOcnU8AMNWs6EY03cLnM39AslqibNa42vf3aj4KwYNoE5wLssrMfoLedav wVGNlcj1RNvIg8EETINZ+EPru8LNJy8FHh4K0Q6Y8yLX9gE7a0Yii3fnVrdHiW3oNoQ3 UcnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=wunner.de); spf=pass (google.com: domain of linux-kernel+bounces-152370-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152370-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d7-20020a17090a498700b0029fc4a56910si6926921pjh.46.2024.04.20.13.07.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 13:07:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152370-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=wunner.de); spf=pass (google.com: domain of linux-kernel+bounces-152370-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152370-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8E35C2816A6 for ; Sat, 20 Apr 2024 20:07:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36BFC4644C; Sat, 20 Apr 2024 20:07:38 +0000 (UTC) Received: from bmailout3.hostsharing.net (bmailout3.hostsharing.net [176.9.242.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 550ED374F7; Sat, 20 Apr 2024 20:07:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=176.9.242.62 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713643657; cv=none; b=vDjbuslxXaL1qvoPU3wJZAIftTSAnL7UNHUtzGnUavanwbYy+xUg+DzzcPcTOJ8Qw7ZrgflZo+n/GoGMBVm3PYHTUZcEvqQTH1HEVjqNzvPJ2KHk3voLiSoeUlrBpgRrSoikkTZtYMZudgfWLf4lpMtV6vBKA6uSf3FzpQcP6EA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713643657; c=relaxed/simple; bh=N2bafYYP+b4kw+NKMOsMMvGGjOuIQlEGeTYftOJBCZI=; h=Message-ID:In-Reply-To:References:From:Date:Subject:To:Cc; b=tTpcRCUH0nok4yFmBvxOBwMSjB0N0rpdhbWKJZYWyJozqPM9e2iPkCf06Pe+tfPA9b53g9KuHrJ31f/5e7+19aqYXk5ZhrRTbEBTjBWfs3yDZcqcFsxqErKC/769LqySr4Bz4pbNzo5omTk65EWmMO5UjecGX6fF+oXphM2HW0E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de; spf=pass smtp.mailfrom=wunner.de; arc=none smtp.client-ip=176.9.242.62 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wunner.de Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS RSA CA G1" (verified OK)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id ED4D01003D027; Sat, 20 Apr 2024 22:07:32 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id C669A1D3F8; Sat, 20 Apr 2024 22:07:32 +0200 (CEST) Message-ID: <3ae8c9a73fbb291c1c863777af175c657a2a10e9.1713608122.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Sat, 20 Apr 2024 22:00:05 +0200 Subject: [PATCH 5/6] platform/x86: Use device_show_string() helper for sysfs attributes To: Greg Kroah-Hartman , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Cc: Corentin Chary , "Luke D. Jones" , "Henrique de Moraes Holschuh" , ibm-acpi-devel@lists.sourceforge.net, Azael Avalos , Hans de Goede , "Ilpo Jaervinen" , platform-driver-x86@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Deduplicate sysfs ->show() callbacks which expose a string at a static memory location. Use the newly introduced device_show_string() helper in the driver core instead by declaring those sysfs attributes with DEVICE_STRING_ATTR_RO(). No functional change intended. Signed-off-by: Lukas Wunner --- drivers/platform/x86/asus-wmi.c | 62 +++++++--------------------- drivers/platform/x86/thinkpad_acpi.c | 10 +---- drivers/platform/x86/toshiba_acpi.c | 9 +--- 3 files changed, 20 insertions(+), 61 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 3f07bbf809ef..78d7579b2fdd 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -915,17 +915,12 @@ static ssize_t kbd_rgb_mode_store(struct device *dev, } static DEVICE_ATTR_WO(kbd_rgb_mode); -static ssize_t kbd_rgb_mode_index_show(struct device *device, - struct device_attribute *attr, - char *buf) -{ - return sysfs_emit(buf, "%s\n", "cmd mode red green blue speed"); -} -static DEVICE_ATTR_RO(kbd_rgb_mode_index); +static DEVICE_STRING_ATTR_RO(kbd_rgb_mode_index, 0444, + "cmd mode red green blue speed"); static struct attribute *kbd_rgb_mode_attrs[] = { &dev_attr_kbd_rgb_mode.attr, - &dev_attr_kbd_rgb_mode_index.attr, + &dev_attr_kbd_rgb_mode_index.attr.attr, NULL, }; @@ -967,17 +962,12 @@ static ssize_t kbd_rgb_state_store(struct device *dev, } static DEVICE_ATTR_WO(kbd_rgb_state); -static ssize_t kbd_rgb_state_index_show(struct device *device, - struct device_attribute *attr, - char *buf) -{ - return sysfs_emit(buf, "%s\n", "cmd boot awake sleep keyboard"); -} -static DEVICE_ATTR_RO(kbd_rgb_state_index); +static DEVICE_STRING_ATTR_RO(kbd_rgb_state_index, 0444, + "cmd boot awake sleep keyboard"); static struct attribute *kbd_rgb_state_attrs[] = { &dev_attr_kbd_rgb_state.attr, - &dev_attr_kbd_rgb_state_index.attr, + &dev_attr_kbd_rgb_state_index.attr.attr, NULL, }; @@ -2493,13 +2483,6 @@ static ssize_t pwm1_enable_store(struct device *dev, return count; } -static ssize_t fan1_label_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return sysfs_emit(buf, "%s\n", ASUS_FAN_DESC); -} - static ssize_t asus_hwmon_temp1(struct device *dev, struct device_attribute *attr, char *buf) @@ -2534,13 +2517,6 @@ static ssize_t fan2_input_show(struct device *dev, return sysfs_emit(buf, "%d\n", value * 100); } -static ssize_t fan2_label_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return sysfs_emit(buf, "%s\n", ASUS_GPU_FAN_DESC); -} - /* Middle/Center fan on modern ROG laptops */ static ssize_t fan3_input_show(struct device *dev, struct device_attribute *attr, @@ -2559,13 +2535,6 @@ static ssize_t fan3_input_show(struct device *dev, return sysfs_emit(buf, "%d\n", value * 100); } -static ssize_t fan3_label_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return sysfs_emit(buf, "%s\n", ASUS_MID_FAN_DESC); -} - static ssize_t pwm2_enable_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -2662,15 +2631,16 @@ static ssize_t pwm3_enable_store(struct device *dev, static DEVICE_ATTR_RW(pwm1); static DEVICE_ATTR_RW(pwm1_enable); static DEVICE_ATTR_RO(fan1_input); -static DEVICE_ATTR_RO(fan1_label); +static DEVICE_STRING_ATTR_RO(fan1_label, 0444, ASUS_FAN_DESC); + /* Fan2 - GPU fan */ static DEVICE_ATTR_RW(pwm2_enable); static DEVICE_ATTR_RO(fan2_input); -static DEVICE_ATTR_RO(fan2_label); +static DEVICE_STRING_ATTR_RO(fan2_label, 0444, ASUS_GPU_FAN_DESC); /* Fan3 - Middle/center fan */ static DEVICE_ATTR_RW(pwm3_enable); static DEVICE_ATTR_RO(fan3_input); -static DEVICE_ATTR_RO(fan3_label); +static DEVICE_STRING_ATTR_RO(fan3_label, 0444, ASUS_MID_FAN_DESC); /* Temperature */ static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL); @@ -2681,11 +2651,11 @@ static struct attribute *hwmon_attributes[] = { &dev_attr_pwm2_enable.attr, &dev_attr_pwm3_enable.attr, &dev_attr_fan1_input.attr, - &dev_attr_fan1_label.attr, + &dev_attr_fan1_label.attr.attr, &dev_attr_fan2_input.attr, - &dev_attr_fan2_label.attr, + &dev_attr_fan2_label.attr.attr, &dev_attr_fan3_input.attr, - &dev_attr_fan3_label.attr, + &dev_attr_fan3_label.attr.attr, &dev_attr_temp1_input.attr, NULL @@ -2702,17 +2672,17 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj, if (asus->fan_type != FAN_TYPE_AGFN) return 0; } else if (attr == &dev_attr_fan1_input.attr - || attr == &dev_attr_fan1_label.attr + || attr == &dev_attr_fan1_label.attr.attr || attr == &dev_attr_pwm1_enable.attr) { if (asus->fan_type == FAN_TYPE_NONE) return 0; } else if (attr == &dev_attr_fan2_input.attr - || attr == &dev_attr_fan2_label.attr + || attr == &dev_attr_fan2_label.attr.attr || attr == &dev_attr_pwm2_enable.attr) { if (asus->gpu_fan_type == FAN_TYPE_NONE) return 0; } else if (attr == &dev_attr_fan3_input.attr - || attr == &dev_attr_fan3_label.attr + || attr == &dev_attr_fan3_label.attr.attr || attr == &dev_attr_pwm3_enable.attr) { if (asus->mid_fan_type == FAN_TYPE_NONE) return 0; diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 82429e59999d..47a64a213d14 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -10991,13 +10991,7 @@ static struct ibm_struct auxmac_data = { .name = "auxmac", }; -static ssize_t auxmac_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - return sysfs_emit(buf, "%s\n", auxmac); -} -static DEVICE_ATTR_RO(auxmac); +static DEVICE_STRING_ATTR_RO(auxmac, 0444, auxmac); static umode_t auxmac_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) @@ -11006,7 +11000,7 @@ static umode_t auxmac_attr_is_visible(struct kobject *kobj, } static struct attribute *auxmac_attributes[] = { - &dev_attr_auxmac.attr, + &dev_attr_auxmac.attr.attr, NULL }; diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 291f14ef6702..01cf60a015bf 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -1814,12 +1814,7 @@ static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work); /* * Sysfs files */ -static ssize_t version_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION); -} -static DEVICE_ATTR_RO(version); +static DEVICE_STRING_ATTR_RO(version, 0444, TOSHIBA_ACPI_VERSION); static ssize_t fan_store(struct device *dev, struct device_attribute *attr, @@ -2428,7 +2423,7 @@ static ssize_t cooling_method_store(struct device *dev, static DEVICE_ATTR_RW(cooling_method); static struct attribute *toshiba_attributes[] = { - &dev_attr_version.attr, + &dev_attr_version.attr.attr, &dev_attr_fan.attr, &dev_attr_kbd_backlight_mode.attr, &dev_attr_kbd_type.attr, -- 2.43.0