Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 3182459

Browse files
l1kgregkh
authored andcommitted
platform/x86: Use device_show_string() helper for sysfs attributes
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 <lukas@wunner.de> Acked-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/3ae8c9a73fbb291c1c863777af175c657a2a10e9.1713608122.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b91b73a commit 3182459

File tree

3 files changed

+20
-61
lines changed

3 files changed

+20
-61
lines changed

drivers/platform/x86/asus-wmi.c

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -915,17 +915,12 @@ static ssize_t kbd_rgb_mode_store(struct device *dev,
915915
}
916916
static DEVICE_ATTR_WO(kbd_rgb_mode);
917917

918-
static ssize_t kbd_rgb_mode_index_show(struct device *device,
919-
struct device_attribute *attr,
920-
char *buf)
921-
{
922-
return sysfs_emit(buf, "%s\n", "cmd mode red green blue speed");
923-
}
924-
static DEVICE_ATTR_RO(kbd_rgb_mode_index);
918+
static DEVICE_STRING_ATTR_RO(kbd_rgb_mode_index, 0444,
919+
"cmd mode red green blue speed");
925920

926921
static struct attribute *kbd_rgb_mode_attrs[] = {
927922
&dev_attr_kbd_rgb_mode.attr,
928-
&dev_attr_kbd_rgb_mode_index.attr,
923+
&dev_attr_kbd_rgb_mode_index.attr.attr,
929924
NULL,
930925
};
931926

@@ -967,17 +962,12 @@ static ssize_t kbd_rgb_state_store(struct device *dev,
967962
}
968963
static DEVICE_ATTR_WO(kbd_rgb_state);
969964

970-
static ssize_t kbd_rgb_state_index_show(struct device *device,
971-
struct device_attribute *attr,
972-
char *buf)
973-
{
974-
return sysfs_emit(buf, "%s\n", "cmd boot awake sleep keyboard");
975-
}
976-
static DEVICE_ATTR_RO(kbd_rgb_state_index);
965+
static DEVICE_STRING_ATTR_RO(kbd_rgb_state_index, 0444,
966+
"cmd boot awake sleep keyboard");
977967

978968
static struct attribute *kbd_rgb_state_attrs[] = {
979969
&dev_attr_kbd_rgb_state.attr,
980-
&dev_attr_kbd_rgb_state_index.attr,
970+
&dev_attr_kbd_rgb_state_index.attr.attr,
981971
NULL,
982972
};
983973

@@ -2493,13 +2483,6 @@ static ssize_t pwm1_enable_store(struct device *dev,
24932483
return count;
24942484
}
24952485

2496-
static ssize_t fan1_label_show(struct device *dev,
2497-
struct device_attribute *attr,
2498-
char *buf)
2499-
{
2500-
return sysfs_emit(buf, "%s\n", ASUS_FAN_DESC);
2501-
}
2502-
25032486
static ssize_t asus_hwmon_temp1(struct device *dev,
25042487
struct device_attribute *attr,
25052488
char *buf)
@@ -2534,13 +2517,6 @@ static ssize_t fan2_input_show(struct device *dev,
25342517
return sysfs_emit(buf, "%d\n", value * 100);
25352518
}
25362519

2537-
static ssize_t fan2_label_show(struct device *dev,
2538-
struct device_attribute *attr,
2539-
char *buf)
2540-
{
2541-
return sysfs_emit(buf, "%s\n", ASUS_GPU_FAN_DESC);
2542-
}
2543-
25442520
/* Middle/Center fan on modern ROG laptops */
25452521
static ssize_t fan3_input_show(struct device *dev,
25462522
struct device_attribute *attr,
@@ -2559,13 +2535,6 @@ static ssize_t fan3_input_show(struct device *dev,
25592535
return sysfs_emit(buf, "%d\n", value * 100);
25602536
}
25612537

2562-
static ssize_t fan3_label_show(struct device *dev,
2563-
struct device_attribute *attr,
2564-
char *buf)
2565-
{
2566-
return sysfs_emit(buf, "%s\n", ASUS_MID_FAN_DESC);
2567-
}
2568-
25692538
static ssize_t pwm2_enable_show(struct device *dev,
25702539
struct device_attribute *attr,
25712540
char *buf)
@@ -2662,15 +2631,16 @@ static ssize_t pwm3_enable_store(struct device *dev,
26622631
static DEVICE_ATTR_RW(pwm1);
26632632
static DEVICE_ATTR_RW(pwm1_enable);
26642633
static DEVICE_ATTR_RO(fan1_input);
2665-
static DEVICE_ATTR_RO(fan1_label);
2634+
static DEVICE_STRING_ATTR_RO(fan1_label, 0444, ASUS_FAN_DESC);
2635+
26662636
/* Fan2 - GPU fan */
26672637
static DEVICE_ATTR_RW(pwm2_enable);
26682638
static DEVICE_ATTR_RO(fan2_input);
2669-
static DEVICE_ATTR_RO(fan2_label);
2639+
static DEVICE_STRING_ATTR_RO(fan2_label, 0444, ASUS_GPU_FAN_DESC);
26702640
/* Fan3 - Middle/center fan */
26712641
static DEVICE_ATTR_RW(pwm3_enable);
26722642
static DEVICE_ATTR_RO(fan3_input);
2673-
static DEVICE_ATTR_RO(fan3_label);
2643+
static DEVICE_STRING_ATTR_RO(fan3_label, 0444, ASUS_MID_FAN_DESC);
26742644

26752645
/* Temperature */
26762646
static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);
@@ -2681,11 +2651,11 @@ static struct attribute *hwmon_attributes[] = {
26812651
&dev_attr_pwm2_enable.attr,
26822652
&dev_attr_pwm3_enable.attr,
26832653
&dev_attr_fan1_input.attr,
2684-
&dev_attr_fan1_label.attr,
2654+
&dev_attr_fan1_label.attr.attr,
26852655
&dev_attr_fan2_input.attr,
2686-
&dev_attr_fan2_label.attr,
2656+
&dev_attr_fan2_label.attr.attr,
26872657
&dev_attr_fan3_input.attr,
2688-
&dev_attr_fan3_label.attr,
2658+
&dev_attr_fan3_label.attr.attr,
26892659

26902660
&dev_attr_temp1_input.attr,
26912661
NULL
@@ -2702,17 +2672,17 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,
27022672
if (asus->fan_type != FAN_TYPE_AGFN)
27032673
return 0;
27042674
} else if (attr == &dev_attr_fan1_input.attr
2705-
|| attr == &dev_attr_fan1_label.attr
2675+
|| attr == &dev_attr_fan1_label.attr.attr
27062676
|| attr == &dev_attr_pwm1_enable.attr) {
27072677
if (asus->fan_type == FAN_TYPE_NONE)
27082678
return 0;
27092679
} else if (attr == &dev_attr_fan2_input.attr
2710-
|| attr == &dev_attr_fan2_label.attr
2680+
|| attr == &dev_attr_fan2_label.attr.attr
27112681
|| attr == &dev_attr_pwm2_enable.attr) {
27122682
if (asus->gpu_fan_type == FAN_TYPE_NONE)
27132683
return 0;
27142684
} else if (attr == &dev_attr_fan3_input.attr
2715-
|| attr == &dev_attr_fan3_label.attr
2685+
|| attr == &dev_attr_fan3_label.attr.attr
27162686
|| attr == &dev_attr_pwm3_enable.attr) {
27172687
if (asus->mid_fan_type == FAN_TYPE_NONE)
27182688
return 0;

drivers/platform/x86/thinkpad_acpi.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10991,13 +10991,7 @@ static struct ibm_struct auxmac_data = {
1099110991
.name = "auxmac",
1099210992
};
1099310993

10994-
static ssize_t auxmac_show(struct device *dev,
10995-
struct device_attribute *attr,
10996-
char *buf)
10997-
{
10998-
return sysfs_emit(buf, "%s\n", auxmac);
10999-
}
11000-
static DEVICE_ATTR_RO(auxmac);
10994+
static DEVICE_STRING_ATTR_RO(auxmac, 0444, auxmac);
1100110995

1100210996
static umode_t auxmac_attr_is_visible(struct kobject *kobj,
1100310997
struct attribute *attr, int n)
@@ -11006,7 +11000,7 @@ static umode_t auxmac_attr_is_visible(struct kobject *kobj,
1100611000
}
1100711001

1100811002
static struct attribute *auxmac_attributes[] = {
11009-
&dev_attr_auxmac.attr,
11003+
&dev_attr_auxmac.attr.attr,
1101011004
NULL
1101111005
};
1101211006

drivers/platform/x86/toshiba_acpi.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,12 +1815,7 @@ static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
18151815
/*
18161816
* Sysfs files
18171817
*/
1818-
static ssize_t version_show(struct device *dev,
1819-
struct device_attribute *attr, char *buf)
1820-
{
1821-
return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1822-
}
1823-
static DEVICE_ATTR_RO(version);
1818+
static DEVICE_STRING_ATTR_RO(version, 0444, TOSHIBA_ACPI_VERSION);
18241819

18251820
static ssize_t fan_store(struct device *dev,
18261821
struct device_attribute *attr,
@@ -2429,7 +2424,7 @@ static ssize_t cooling_method_store(struct device *dev,
24292424
static DEVICE_ATTR_RW(cooling_method);
24302425

24312426
static struct attribute *toshiba_attributes[] = {
2432-
&dev_attr_version.attr,
2427+
&dev_attr_version.attr.attr,
24332428
&dev_attr_fan.attr,
24342429
&dev_attr_kbd_backlight_mode.attr,
24352430
&dev_attr_kbd_type.attr,

0 commit comments

Comments
 (0)