Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: amd-pstate: fix global sysfs attribute type

In commit 3666062b87ec ("cpufreq: amd-pstate: move to use bus_get_dev_root()")
the "amd_pstate" attributes where moved from a dedicated kobject to the
cpu root kobject.

While the dedicated kobject expects to contain kobj_attributes the root
kobject needs device_attributes.

As the changed arguments are not used by the callbacks it works most of
the time.
However CFI will detect this issue:

[ 4947.849350] CFI failure at dev_attr_show+0x24/0x60 (target: show_status+0x0/0x70; expected type: 0x8651b1de)
...
[ 4947.849409] Call Trace:
[ 4947.849410] <TASK>
[ 4947.849411] ? __warn+0xcf/0x1c0
[ 4947.849414] ? dev_attr_show+0x24/0x60
[ 4947.849415] ? report_cfi_failure+0x4e/0x60
[ 4947.849417] ? handle_cfi_failure+0x14c/0x1d0
[ 4947.849419] ? __cfi_show_status+0x10/0x10
[ 4947.849420] ? handle_bug+0x4f/0x90
[ 4947.849421] ? exc_invalid_op+0x1a/0x60
[ 4947.849422] ? asm_exc_invalid_op+0x1a/0x20
[ 4947.849424] ? __cfi_show_status+0x10/0x10
[ 4947.849425] ? dev_attr_show+0x24/0x60
[ 4947.849426] sysfs_kf_seq_show+0xa6/0x110
[ 4947.849433] seq_read_iter+0x16c/0x4b0
[ 4947.849436] vfs_read+0x272/0x2d0
[ 4947.849438] ksys_read+0x72/0xe0
[ 4947.849439] do_syscall_64+0x76/0xb0
[ 4947.849440] ? do_user_addr_fault+0x252/0x650
[ 4947.849442] ? exc_page_fault+0x7a/0x1b0
[ 4947.849443] entry_SYSCALL_64_after_hwframe+0x72/0xdc

Fixes: 3666062b87ec ("cpufreq: amd-pstate: move to use bus_get_dev_root()")
Reported-by: Jannik Glückert <jannik.glueckert@gmail.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217765
Link: https://lore.kernel.org/lkml/c7f1bf9b-b183-bf6e-1cbb-d43f72494083@gmail.com/
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Thomas Weißschuh and committed by
Rafael J. Wysocki
5e720f8c 52a93d39

+5 -5
+5 -5
drivers/cpufreq/amd-pstate.c
··· 1012 1012 return 0; 1013 1013 } 1014 1014 1015 - static ssize_t show_status(struct kobject *kobj, 1016 - struct kobj_attribute *attr, char *buf) 1015 + static ssize_t status_show(struct device *dev, 1016 + struct device_attribute *attr, char *buf) 1017 1017 { 1018 1018 ssize_t ret; 1019 1019 ··· 1024 1024 return ret; 1025 1025 } 1026 1026 1027 - static ssize_t store_status(struct kobject *a, struct kobj_attribute *b, 1027 + static ssize_t status_store(struct device *a, struct device_attribute *b, 1028 1028 const char *buf, size_t count) 1029 1029 { 1030 1030 char *p = memchr(buf, '\n', count); ··· 1043 1043 cpufreq_freq_attr_ro(amd_pstate_highest_perf); 1044 1044 cpufreq_freq_attr_rw(energy_performance_preference); 1045 1045 cpufreq_freq_attr_ro(energy_performance_available_preferences); 1046 - define_one_global_rw(status); 1046 + static DEVICE_ATTR_RW(status); 1047 1047 1048 1048 static struct freq_attr *amd_pstate_attr[] = { 1049 1049 &amd_pstate_max_freq, ··· 1062 1062 }; 1063 1063 1064 1064 static struct attribute *pstate_global_attributes[] = { 1065 - &status.attr, 1065 + &dev_attr_status.attr, 1066 1066 NULL 1067 1067 }; 1068 1068