drivers core: Use sysfs_emit functions
Subsystems (8)
cover drivers core: Use sysfs_emit functions
This is a sample block of conversions for drivers/base from next-20200903. It requires the suggested patch that adds sysfs_emit pafunctions from
https://lore.kernel.org/lkml/a9054fb521e65f2809671fa9c18e2453061e9d91.1598744610.git.joe@perches.com/
Convert and neaten the various uses of sprintf family functions to sysfs_emit and sysfs_emit_at
Joe Perches (4):
drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions drivers core: Remove strcat uses around sysfs_emit and neaten drivers core: Reindent a couple uses around sysfs_emit
drivers core: Miscellaneous changes for sysfs_emit
drivers/base/arch_topology.c | 2 +- drivers/base/cacheinfo.c | 32 ++++++++----- drivers/base/class.c | 2 +- drivers/base/core.c | 27 ++++++----- drivers/base/cpu.c | 50 ++++++++++---------- drivers/base/dd.c | 2 +- drivers/base/firmware_loader/fallback.c | 2 +- drivers/base/memory.c | 59 +++++++++++------------ drivers/base/node.c | 47 ++++++++---------- drivers/base/platform.c | 8 ++-- drivers/base/power/sysfs.c | 63 +++++++++++++------------ drivers/base/power/wakeup_stats.c | 12 ++--- drivers/base/soc.c | 10 ++-- 13 files changed, 159 insertions(+), 157 deletions(-)
Signature · 1 line
2.26.0
PATCH 1/4 drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
Convert the various sprintf fmaily calls in sysfs device show functions to sysfs_emit and sysfs_emit_at for PAGE_SIZE buffer safety.
Done with:
$ spatch -sp-file sysfs_emit_dev.cocci --in-place --max-width=80 .
And cocci script:
$ cat sysfs_emit_dev.cocci @@ identifier d_show; identifier dev, attr, buf; @@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
}@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}@@
identifier d_show;
identifier dev, attr, buf;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
}@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
return
- strcpy(buf, chr);
+ sysfs_emit(buf, chr);
...>
}@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- sprintf(buf,
+ sysfs_emit(buf,
...);
...>
return len;
}@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- snprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
len =
- scnprintf(buf, PAGE_SIZE,
+ sysfs_emit(buf,
...);
...>
return len;
}@@
identifier d_show;
identifier dev, attr, buf;
identifier len;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
<...
- len += scnprintf(buf + len, PAGE_SIZE - len,
+ len += sysfs_emit_at(buf, len,
...);
...>
return len;
}@@
identifier d_show;
identifier dev, attr, buf;
expression chr;
@@
ssize_t d_show(struct device *dev, struct device_attribute *attr, char *buf)
{
...- strcpy(buf, chr);
- return strlen(buf);
+ return sysfs_emit(buf, chr);
}
--- drivers/base/arch_topology.c | 2 +- drivers/base/cacheinfo.c | 18 ++++----- drivers/base/core.c | 19 +++++----- drivers/base/cpu.c | 32 ++++++++-------- drivers/base/dd.c | 2 +- drivers/base/firmware_loader/fallback.c | 2 +- drivers/base/memory.c | 24 ++++++------ drivers/base/node.c | 28 +++++++------- drivers/base/platform.c | 4 +- drivers/base/power/sysfs.c | 50 ++++++++++++------------- drivers/base/power/wakeup_stats.c | 12 +++--- drivers/base/soc.c | 10 ++--- 12 files changed, 102 insertions(+), 101 deletions(-)
drivers/base/arch_topology.c +1 -1
@@ -71,7 +71,7 @@ static ssize_t cpu_capacity_show(struct device *dev, { struct cpu *cpu = container_of(dev, struct cpu, dev); -return sprintf (buf,"%lu\n" ,topology_get_cpu_scale (cpu->dev.id)); +return sysfs_emit (buf,"%lu\n" ,topology_get_cpu_scale (cpu->dev.id)); }static void update_topology_flags_workfn (struct work_struct *work);
drivers/base/cacheinfo.c +9 -9
@@ -377,7 +377,7 @@ static ssize_t size_show(struct device *dev, {struct cacheinfo *this_leaf =dev_get_drvdata (dev); -return sprintf (buf,"%uK\n" , this_leaf->size >>10 ); +return sysfs_emit (buf,"%uK\n" , this_leaf->size >>10 ); }static ssize_t shared_cpumap_show_func (struct device *dev,bool list,char *buf)
@@ -407,11 +407,11 @@ static ssize_t type_show(struct device *dev,switch (this_leaf->type) {case CACHE_TYPE_DATA : -return sprintf (buf,"Data\n" ); +return sysfs_emit (buf,"Data\n" );case CACHE_TYPE_INST : -return sprintf (buf,"Instruction\n" ); +return sysfs_emit (buf,"Instruction\n" );case CACHE_TYPE_UNIFIED : -return sprintf (buf,"Unified\n" ); +return sysfs_emit (buf,"Unified\n" );default :return -EINVAL ; }
@@ -425,11 +425,11 @@ static ssize_t allocation_policy_show(struct device *dev,int n =0 ;if ((ci_attr &CACHE_READ_ALLOCATE ) && (ci_attr &CACHE_WRITE_ALLOCATE )) - n =sprintf (buf,"ReadWriteAllocate\n" ); + n =sysfs_emit (buf,"ReadWriteAllocate\n" );else if (ci_attr &CACHE_READ_ALLOCATE ) - n =sprintf (buf,"ReadAllocate\n" ); + n =sysfs_emit (buf,"ReadAllocate\n" );else if (ci_attr &CACHE_WRITE_ALLOCATE ) - n =sprintf (buf,"WriteAllocate\n" ); + n =sysfs_emit (buf,"WriteAllocate\n" );return n; }
@@ -441,9 +441,9 @@ static ssize_t write_policy_show(struct device *dev,int n =0 ;if (ci_attr &CACHE_WRITE_THROUGH ) - n =sprintf (buf,"WriteThrough\n" ); + n =sysfs_emit (buf,"WriteThrough\n" );else if (ci_attr &CACHE_WRITE_BACK ) - n =sprintf (buf,"WriteBack\n" ); + n =sysfs_emit (buf,"WriteBack\n" );return n; }
drivers/base/core.c +10 -9
@@ -259,7 +259,7 @@ static ssize_t status_show(struct device *dev,default : status ="unknown" ;break ; } -return sprintf (buf,"%s\n" , status); +return sysfs_emit (buf,"%s\n" , status); }static DEVICE_ATTR_RO (status);
@@ -276,7 +276,7 @@ static ssize_t auto_remove_on_show(struct device *dev,else str ="never" ; -return sprintf (buf,"%s\n" , str); +return sysfs_emit (buf,"%s\n" , str); }static DEVICE_ATTR_RO (auto_remove_on);
@@ -285,7 +285,7 @@ static ssize_t runtime_pm_show(struct device *dev, {struct device_link *link =to_devlink (dev); -return sprintf (buf,"%d\n" , !!(link->flags &DL_FLAG_PM_RUNTIME )); +return sysfs_emit (buf,"%d\n" , !!(link->flags &DL_FLAG_PM_RUNTIME )); }static DEVICE_ATTR_RO (runtime_pm);
@@ -294,7 +294,8 @@ static ssize_t sync_state_only_show(struct device *dev, {struct device_link *link =to_devlink (dev); -return sprintf (buf,"%d\n" , !!(link->flags &DL_FLAG_SYNC_STATE_ONLY )); +return sysfs_emit (buf,"%d\n" , + !!(link->flags &DL_FLAG_SYNC_STATE_ONLY )); }static DEVICE_ATTR_RO (sync_state_only);
@@ -1063,7 +1064,7 @@ static ssize_t waiting_for_supplier_show(struct device *dev, && dev->links.need_for_probe;mutex_unlock (&wfs_lock);device_unlock (dev); -return sprintf (buf,"%u\n" , val); +return sysfs_emit (buf,"%u\n" , val); }static DEVICE_ATTR_RO (waiting_for_supplier);
@@ -1713,7 +1714,7 @@ ssize_t device_show_ulong(struct device *dev, char *buf) {struct dev_ext_attribute *ea =to_ext_attr (attr); -return snprintf (buf,PAGE_SIZE ,"%lx\n" , *(unsigned long *)(ea->var)); +return sysfs_emit (buf,"%lx\n" , *(unsigned long *)(ea->var)); }EXPORT_SYMBOL_GPL (device_show_ulong);
@@ -1743,7 +1744,7 @@ ssize_t device_show_int(struct device *dev, {struct dev_ext_attribute *ea =to_ext_attr (attr); -return snprintf (buf,PAGE_SIZE ,"%d\n" , *(int *)(ea->var)); +return sysfs_emit (buf,"%d\n" , *(int *)(ea->var)); }EXPORT_SYMBOL_GPL (device_show_int);
@@ -1764,7 +1765,7 @@ ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, {struct dev_ext_attribute *ea =to_ext_attr (attr); -return snprintf (buf,PAGE_SIZE ,"%d\n" , *(bool *)(ea->var)); +return sysfs_emit (buf,"%d\n" , *(bool *)(ea->var)); }EXPORT_SYMBOL_GPL (device_show_bool);
@@ -1998,7 +1999,7 @@ static ssize_t online_show(struct device *dev, struct device_attribute *attr,device_lock (dev); val = !dev->offline;device_unlock (dev); -return sprintf (buf,"%u\n" , val); +return sysfs_emit (buf,"%u\n" , val); } static ssize_t online_store(struct device *dev, struct device_attribute *attr,
drivers/base/cpu.c +16 -16
@@ -156,7 +156,7 @@ static ssize_t show_crash_notes(struct device *dev, struct device_attribute *att* operation should be safe. No locking required. */ addr =per_cpu_ptr_to_phys (per_cpu_ptr (crash_notes, cpunum)); - rc =sprintf (buf,"%Lx\n" , addr); + rc =sysfs_emit (buf,"%Lx\n" , addr);return rc; } static DEVICE_ATTR(crash_notes, 0400, show_crash_notes, NULL);
@@ -167,7 +167,7 @@ static ssize_t show_crash_notes_size(struct device *dev, {ssize_t rc; - rc =sprintf (buf,"%zu\n" ,sizeof (note_buf_t)); + rc =sysfs_emit (buf,"%zu\n" ,sizeof (note_buf_t));return rc; } static DEVICE_ATTR(crash_notes_size, 0400, show_crash_notes_size, NULL);
@@ -231,7 +231,7 @@ static struct cpu_attr cpu_attrs[] = {static ssize_t print_cpus_kernel_max (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%d\n" ,NR_CPUS -1 ); +return sysfs_emit (buf,"%d\n" ,NR_CPUS -1 ); } static DEVICE_ATTR(kernel_max, 0444, print_cpus_kernel_max, NULL);
@@ -279,7 +279,7 @@ static ssize_t print_cpus_isolated(struct device *dev,cpumask_andnot (isolated, cpu_possible_mask,housekeeping_cpumask (HK_FLAG_DOMAIN )); - n =sprintf (buf,"%*pbl\n" ,cpumask_pr_args (isolated)); + n =sysfs_emit (buf,"%*pbl\n" ,cpumask_pr_args (isolated));free_cpumask_var (isolated);
@@ -291,7 +291,7 @@ static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL);static ssize_t print_cpus_nohz_full (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%*pbl\n" ,cpumask_pr_args (tick_nohz_full_mask)); +return sysfs_emit (buf,"%*pbl\n" ,cpumask_pr_args (tick_nohz_full_mask)); } static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL);#endif
@@ -323,8 +323,8 @@ static ssize_t print_cpu_modalias(struct device *dev,ssize_t n;u32 i; - n =sprintf (buf,"cpu:type:" CPU_FEATURE_TYPEFMT ":feature:" , -CPU_FEATURE_TYPEVAL ); + n =sysfs_emit (buf,"cpu:type:" CPU_FEATURE_TYPEFMT ":feature:" , +CPU_FEATURE_TYPEVAL );for (i =0 ; i <MAX_CPU_FEATURES ; i++)if (cpu_have_feature (i)) {
@@ -516,56 +516,56 @@ static void __init cpu_dev_register_generic(void)ssize_t __weak cpu_show_meltdown (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_spectre_v1 (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_spectre_v2 (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_spec_store_bypass (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_l1tf (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_mds (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_tsx_async_abort (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_itlb_multihit (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); }ssize_t __weak cpu_show_srbds (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"Not affected\n" ); +return sysfs_emit (buf,"Not affected\n" ); } static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL);
drivers/base/dd.c +1 -1
@@ -486,7 +486,7 @@ static ssize_t state_synced_show(struct device *dev,device_lock (dev); val = dev->state_synced;device_unlock (dev); -return sprintf (buf,"%u\n" , val); +return sysfs_emit (buf,"%u\n" , val); }static DEVICE_ATTR_RO (state_synced);
drivers/base/firmware_loader/fallback.c +1 -1
@@ -219,7 +219,7 @@ static ssize_t firmware_loading_show(struct device *dev, loading =fw_sysfs_loading (fw_sysfs->fw_priv);mutex_unlock (&fw_lock); -return sprintf (buf,"%d\n" , loading); +return sysfs_emit (buf,"%d\n" , loading); }/**
drivers/base/memory.c +12 -12
@@ -119,7 +119,7 @@ static ssize_t phys_index_show(struct device *dev,unsigned long phys_index; phys_index = mem->start_section_nr / sections_per_block; -return sprintf (buf,"%08lx\n" , phys_index); +return sysfs_emit (buf,"%08lx\n" , phys_index); }/*
@@ -129,7 +129,7 @@ static ssize_t phys_index_show(struct device *dev,static ssize_t removable_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%d\n" , (int )IS_ENABLED (CONFIG_MEMORY_HOTREMOVE )); +return sysfs_emit (buf,"%d\n" , (int )IS_ENABLED (CONFIG_MEMORY_HOTREMOVE )); }/*
@@ -147,17 +147,17 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,*/ switch (mem->state) {case MEM_ONLINE : - len =sprintf (buf,"online\n" ); + len =sysfs_emit (buf,"online\n" );break ;case MEM_OFFLINE : - len =sprintf (buf,"offline\n" ); + len =sysfs_emit (buf,"offline\n" );break ;case MEM_GOING_OFFLINE : - len =sprintf (buf,"going-offline\n" ); + len =sysfs_emit (buf,"going-offline\n" );break ;default : - len =sprintf (buf,"ERROR-UNKNOWN-%ld\n" , - mem->state); + len =sysfs_emit (buf,"ERROR-UNKNOWN-%ld\n" , + mem->state);WARN_ON (1 );break ; }
@@ -303,7 +303,7 @@ static ssize_t phys_device_show(struct device *dev, struct device_attribute *attr, char *buf) { struct memory_block *mem = to_memory_block(dev); -return sprintf (buf,"%d\n" , mem->phys_device); +return sysfs_emit (buf,"%d\n" , mem->phys_device); }#ifdef CONFIG_MEMORY_HOTREMOVE
@@ -341,7 +341,7 @@ static ssize_t valid_zones_show(struct device *dev, default_zone =test_pages_in_a_zone (start_pfn, start_pfn + nr_pages);if (!default_zone) -return sprintf (buf,"none\n" ); +return sysfs_emit (buf,"none\n" );strcat (buf, default_zone->name); goto out; }
@@ -374,7 +374,7 @@ static DEVICE_ATTR_RO(removable);static ssize_t block_size_bytes_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%lx\n" ,memory_block_size_bytes ()); +return sysfs_emit (buf,"%lx\n" ,memory_block_size_bytes ()); }static DEVICE_ATTR_RO (block_size_bytes);
@@ -386,8 +386,8 @@ static DEVICE_ATTR_RO(block_size_bytes);static ssize_t auto_online_blocks_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%s\n" , - online_type_to_str[memhp_default_online_type]); +return sysfs_emit (buf,"%s\n" , + online_type_to_str[memhp_default_online_type]); } static ssize_t auto_online_blocks_store(struct device *dev,
drivers/base/node.c +14 -14
@@ -370,7 +370,7 @@ static ssize_t node_read_meminfo(struct device *dev,si_meminfo_node (&i, nid); sreclaimable =node_page_state_pages (pgdat,NR_SLAB_RECLAIMABLE_B ); sunreclaimable =node_page_state_pages (pgdat,NR_SLAB_UNRECLAIMABLE_B ); - n =sprintf (buf, + n =sysfs_emit (buf,"Node %d MemTotal: %8lu kB\n" "Node %d MemFree: %8lu kB\n" "Node %d MemUsed: %8lu kB\n"
@@ -477,19 +477,19 @@ static DEVICE_ATTR(meminfo, S_IRUGO, node_read_meminfo, NULL);static ssize_t node_read_numastat (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf, -"numa_hit %lu\n" -"numa_miss %lu\n" -"numa_foreign %lu\n" -"interleave_hit %lu\n" -"local_node %lu\n" -"other_node %lu\n" , -sum_zone_numa_state (dev->id,NUMA_HIT ), -sum_zone_numa_state (dev->id,NUMA_MISS ), -sum_zone_numa_state (dev->id,NUMA_FOREIGN ), -sum_zone_numa_state (dev->id,NUMA_INTERLEAVE_HIT ), -sum_zone_numa_state (dev->id,NUMA_LOCAL ), -sum_zone_numa_state (dev->id,NUMA_OTHER )); +return sysfs_emit (buf, +"numa_hit %lu\n" +"numa_miss %lu\n" +"numa_foreign %lu\n" +"interleave_hit %lu\n" +"local_node %lu\n" +"other_node %lu\n" , +sum_zone_numa_state (dev->id,NUMA_HIT ), +sum_zone_numa_state (dev->id,NUMA_MISS ), +sum_zone_numa_state (dev->id,NUMA_FOREIGN ), +sum_zone_numa_state (dev->id,NUMA_INTERLEAVE_HIT ), +sum_zone_numa_state (dev->id,NUMA_LOCAL ), +sum_zone_numa_state (dev->id,NUMA_OTHER )); } static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
drivers/base/platform.c +2 -2
@@ -1070,7 +1070,7 @@ static ssize_t driver_override_show(struct device *dev,ssize_t len;device_lock (dev); - len =sprintf (buf,"%s\n" , pdev->driver_override); + len =sysfs_emit (buf,"%s\n" , pdev->driver_override);device_unlock (dev);return len; }
@@ -1079,7 +1079,7 @@ static DEVICE_ATTR_RW(driver_override);static ssize_t numa_node_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sprintf (buf,"%d\n" ,dev_to_node (dev)); +return sysfs_emit (buf,"%d\n" ,dev_to_node (dev)); }static DEVICE_ATTR_RO (numa_node);
drivers/base/power/sysfs.c +25 -25
135 lines not on this page · raw message
drivers/base/power/wakeup_stats.c +6 -6
@@ -42,7 +42,7 @@ static ssize_t active_time_ms_show(struct device *dev,ktime_t active_time = ws->active ?ktime_sub (ktime_get (), ws->last_time) :0 ; -return sprintf (buf,"%lld\n" ,ktime_to_ms (active_time)); +return sysfs_emit (buf,"%lld\n" ,ktime_to_ms (active_time)); }static DEVICE_ATTR_RO (active_time_ms);
@@ -57,7 +57,7 @@ static ssize_t total_time_ms_show(struct device *dev, active_time =ktime_sub (ktime_get (), ws->last_time); total_time =ktime_add (total_time, active_time); } -return sprintf (buf,"%lld\n" ,ktime_to_ms (total_time)); +return sysfs_emit (buf,"%lld\n" ,ktime_to_ms (total_time)); }static DEVICE_ATTR_RO (total_time_ms);
@@ -73,7 +73,7 @@ static ssize_t max_time_ms_show(struct device *dev,if (active_time > max_time) max_time = active_time; } -return sprintf (buf,"%lld\n" ,ktime_to_ms (max_time)); +return sysfs_emit (buf,"%lld\n" ,ktime_to_ms (max_time)); }static DEVICE_ATTR_RO (max_time_ms);
@@ -82,7 +82,7 @@ static ssize_t last_change_ms_show(struct device *dev, {struct wakeup_source *ws =dev_get_drvdata (dev); -return sprintf (buf,"%lld\n" ,ktime_to_ms (ws->last_time)); +return sysfs_emit (buf,"%lld\n" ,ktime_to_ms (ws->last_time)); }static DEVICE_ATTR_RO (last_change_ms);
@@ -91,7 +91,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, {struct wakeup_source *ws =dev_get_drvdata (dev); -return sprintf (buf,"%s\n" , ws->name); +return sysfs_emit (buf,"%s\n" , ws->name); }static DEVICE_ATTR_RO (name);
@@ -106,7 +106,7 @@ static ssize_t prevent_suspend_time_ms_show(struct device *dev, prevent_sleep_time =ktime_add (prevent_sleep_time,ktime_sub (ktime_get (), ws->start_prevent_time)); } -return sprintf (buf,"%lld\n" ,ktime_to_ms (prevent_sleep_time)); +return sysfs_emit (buf,"%lld\n" ,ktime_to_ms (prevent_sleep_time)); }static DEVICE_ATTR_RO (prevent_suspend_time_ms);
drivers/base/soc.c +5 -5
@@ -76,15 +76,15 @@ static ssize_t soc_info_get(struct device *dev, struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);if (attr == &dev_attr_machine) -return sprintf (buf,"%s\n" , soc_dev->attr->machine); +return sysfs_emit (buf,"%s\n" , soc_dev->attr->machine);if (attr == &dev_attr_family) -return sprintf (buf,"%s\n" , soc_dev->attr->family); +return sysfs_emit (buf,"%s\n" , soc_dev->attr->family);if (attr == &dev_attr_revision) -return sprintf (buf,"%s\n" , soc_dev->attr->revision); +return sysfs_emit (buf,"%s\n" , soc_dev->attr->revision);if (attr == &dev_attr_serial_number) -return sprintf (buf,"%s\n" , soc_dev->attr->serial_number); +return sysfs_emit (buf,"%s\n" , soc_dev->attr->serial_number);if (attr == &dev_attr_soc_id) -return sprintf (buf,"%s\n" , soc_dev->attr->soc_id); +return sysfs_emit (buf,"%s\n" , soc_dev->attr->soc_id);return -EINVAL ;
Signature · 1 line
2.26.0
kernel test robot
build botRe: [PATCH 1/4] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
I love your patch! Yet something to improve:
Hi Joe,
I love your patch! Yet something to improve:
[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on pm/linux-next linus/master v5.9-rc4 next-20200903] [cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 4024823563d05bbe880885c9987d14a7130801da config: i386-randconfig-r003-20200908 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/base/power/sysfs.c: In function 'control_show':
>> drivers/base/power/sysfs.c:104:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
104 | return sysfs_emit(buf, "%s\n",
| ^~~~~~~~~~
| sysfs_init
cc1: some warnings being treated as errors
--
drivers/base/power/wakeup_stats.c: In function 'active_time_ms_show':
>> drivers/base/power/wakeup_stats.c:45:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
45 | return sysfs_emit(buf, "%lld\n", ktime_to_ms(active_time));
| ^~~~~~~~~~
| sysfs_initcc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/b84c60e52b9660261f61439c055783a1aba3d436
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 git checkout b84c60e52b9660261f61439c055783a1aba3d436
vim +104 drivers/base/power/sysfs.c
100
101 static ssize_t control_show(struct device *dev, struct device_attribute *attr,
102 char *buf)
103 {
> 104 return sysfs_emit(buf, "%s\n",
105 dev->power.runtime_auto ? ctrl_auto : ctrl_on);
106 }
107
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH 1/4] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
Quoted 1 line · kernel test robot
Hi Joe,
Hi robot.
Quoted 1 line
I love your patch! Yet something to improve:
Nothing really to improve as these are dependent on a previous patch that this robot did not apply.
kernel test robot
build botRe: [PATCH 1/4] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
In reply to Joe PerchesI love your patch! Yet something to improve:
Hi Joe,
I love your patch! Yet something to improve:
[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on pm/linux-next linus/master v5.9-rc4 next-20200903] [cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 4024823563d05bbe880885c9987d14a7130801da config: h8300-randconfig-r005-20200908 (attached as .config) compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=h8300
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/linux/ioport.h:13,
from include/linux/acpi.h:12,
from drivers/base/core.c:11:
include/linux/scatterlist.h: In function 'sg_set_buf':
include/asm-generic/page.h:93:50: warning: ordered comparison of pointer with null pointer [-Wextra]
93 | #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/base/core.c: In function 'status_show':
>> drivers/base/core.c:262:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
262 | return sysfs_emit(buf, "%s\n", status);
| ^~~~~~~~~~
| sysfs_init
cc1: some warnings being treated as errors
--
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from include/linux/debugfs.h:15,
from drivers/base/dd.c:19:
include/linux/scatterlist.h: In function 'sg_set_buf':
include/asm-generic/page.h:93:50: warning: ordered comparison of pointer with null pointer [-Wextra]
93 | #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/base/dd.c: In function 'state_synced_show':
>> drivers/base/dd.c:489:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
489 | return sysfs_emit(buf, "%u\n", val);
| ^~~~~~~~~~
| sysfs_init cc1: some warnings being treated as errors
--
In file included from include/linux/string.h:6,
from drivers/base/platform.c:12:
include/linux/scatterlist.h: In function 'sg_set_buf':
include/asm-generic/page.h:93:50: warning: ordered comparison of pointer with null pointer [-Wextra]
93 | #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
| ^~
include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
78 | # define unlikely(x) __builtin_expect(!!(x), 0)
| ^
include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~
include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
143 | BUG_ON(!virt_addr_valid(buf));
| ^~~~~~~~~~~~~~~
drivers/base/platform.c: In function 'driver_override_show':
>> drivers/base/platform.c:1073:8: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
1073 | len = sysfs_emit(buf, "%s\n", pdev->driver_override);
| ^~~~~~~~~~
| sysfs_init
drivers/base/platform.c: At top level:
drivers/base/platform.c:1376:20: warning: no previous prototype for 'early_platform_cleanup' [-Wmissing-prototypes]
1376 | void __weak __init early_platform_cleanup(void) { }
| ^~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
drivers/base/cpu.c: In function 'print_cpus_kernel_max':
>> drivers/base/cpu.c:234:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
234 | return sysfs_emit(buf, "%d\n", NR_CPUS - 1);
| ^~~~~~~~~~
| sysfs_init
cc1: some warnings being treated as errors
--
drivers/base/cacheinfo.c: In function 'size_show':
>> drivers/base/cacheinfo.c:380:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
380 | return sysfs_emit(buf, "%uK\n", this_leaf->size >> 10);
| ^~~~~~~~~~
| sysfs_init
cc1: some warnings being treated as errors
--
drivers/base/firmware_loader/fallback.c: In function 'firmware_loading_show':
>> drivers/base/firmware_loader/fallback.c:222:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
222 | return sysfs_emit(buf, "%d\n", loading);
| ^~~~~~~~~~
| sysfs_initcc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/b84c60e52b9660261f61439c055783a1aba3d436
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 git checkout b84c60e52b9660261f61439c055783a1aba3d436
vim +262 drivers/base/core.c
240
241 static ssize_t status_show(struct device *dev,
242 struct device_attribute *attr, char *buf)
243 {
244 char *status;
245
246 switch (to_devlink(dev)->status) {
247 case DL_STATE_NONE:
248 status = "not tracked"; break;
249 case DL_STATE_DORMANT:
250 status = "dormant"; break;
251 case DL_STATE_AVAILABLE:
252 status = "available"; break;
253 case DL_STATE_CONSUMER_PROBE:
254 status = "consumer probing"; break;
255 case DL_STATE_ACTIVE:
256 status = "active"; break;
257 case DL_STATE_SUPPLIER_UNBIND:
258 status = "supplier unbinding"; break;
259 default:
260 status = "unknown"; break;
261 }
> 262 return sysfs_emit(buf, "%s\n", status);
263 }
264 static DEVICE_ATTR_RO(status);
265
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Greg Kroah-Hartman
maintainerRe: [PATCH 1/4] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
In reply to Joe PerchesQuoted 2 lines · Joe Perches
Convert the various sprintf fmaily calls in sysfs device show functions to
sysfs_emitandsysfs_emit_atforPAGE_SIZEbuffer safety.
But no sysfs_emit_at() calls are used in this patch :(
thanks,
greg k-h
Re: [PATCH 1/4] drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions
Quoted 5 lines · Greg Kroah-Hartman
Quoted 2 lines · Joe Perches
Convert the various sprintf fmaily calls in sysfs device show functions to
sysfs_emitandsysfs_emit_atforPAGE_SIZEbuffer safety.But no
sysfs_emit_at()calls are used in this patch :(
Try patch 4.
No instance where it was appropriate to use sysfs_emit_at matched the cocci script requirements in this directory.
PATCH 2/4 drivers core: Remove strcat uses around sysfs_emit and neaten
In reply to Joe Perchesstrcat is no longer necessary for sysfs_emit and sysfs_emit_at uses.
Convert the strcat uses to sysfs_emit calls and neaten other block uses of direct returns to use an intermediate const char *.
--- drivers/base/cacheinfo.c | 26 ++++++++++++++------- drivers/base/core.c | 10 ++++---- drivers/base/memory.c | 47 ++++++++++++++++++-------------------- drivers/base/power/sysfs.c | 23 +++++++++++-------- 4 files changed, 59 insertions(+), 47 deletions(-)
drivers/base/cacheinfo.c +18 -8
@@ -404,17 +404,23 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf) { struct cacheinfo *this_leaf = dev_get_drvdata(dev); +const char *type =NULL ;switch (this_leaf->type) {case CACHE_TYPE_DATA : -return sysfs_emit (buf,"Data\n" ); + type ="Data" ; +break ;case CACHE_TYPE_INST : -return sysfs_emit (buf,"Instruction\n" ); + type ="Instruction" ; +break ;case CACHE_TYPE_UNIFIED : -return sysfs_emit (buf,"Unified\n" ); + type ="Unified" ; +break ;default :return -EINVAL ; } + +return sysfs_emit (buf,"%s\n" , type); } static ssize_t allocation_policy_show(struct device *dev,
@@ -422,15 +428,19 @@ static ssize_t allocation_policy_show(struct device *dev, {struct cacheinfo *this_leaf =dev_get_drvdata (dev);unsigned int ci_attr = this_leaf->attributes; -int n =0 ; +const char *type =NULL ;if ((ci_attr &CACHE_READ_ALLOCATE ) && (ci_attr &CACHE_WRITE_ALLOCATE )) - n =sysfs_emit (buf,"ReadWriteAllocate\n" ); + type ="ReadWriteAllocate" ;else if (ci_attr &CACHE_READ_ALLOCATE ) - n =sysfs_emit (buf,"ReadAllocate\n" ); + type ="ReadAllocate" ;else if (ci_attr &CACHE_WRITE_ALLOCATE ) - n =sysfs_emit (buf,"WriteAllocate\n" ); -return n; + type ="WriteAllocate" ; + +if (!type) +return 0 ; + +return sysfs_emit (buf,"%s\n" , type); } static ssize_t write_policy_show(struct device *dev,
drivers/base/core.c +5 -5
@@ -267,16 +267,16 @@ static ssize_t auto_remove_on_show(struct device *dev, struct device_attribute *attr, char *buf) { struct device_link *link = to_devlink(dev); -char *str; +char *type;if (link->flags &DL_FLAG_AUTOREMOVE_SUPPLIER ) - str ="supplier unbind" ; + type ="supplier unbind" ;else if (link->flags &DL_FLAG_AUTOREMOVE_CONSUMER ) - str ="consumer unbind" ; + type ="consumer unbind" ;else - str ="never" ; + type ="never" ; -return sysfs_emit (buf,"%s\n" , str); +return sysfs_emit (buf,"%s\n" , type); }static DEVICE_ATTR_RO (auto_remove_on);
drivers/base/memory.c +22 -25
98 lines not on this page · raw message
drivers/base/power/sysfs.c +14 -9
@@ -255,9 +255,9 @@ static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev,s32 value =dev_pm_qos_get_user_latency_tolerance (dev);if (value <0 ) -return sysfs_emit (buf,"auto\n" ); +return sysfs_emit (buf,"%s\n" ,"auto" );if (value ==PM_QOS_LATENCY_ANY ) -return sysfs_emit (buf,"any\n" ); +return sysfs_emit (buf,"%s\n" ,"any" );return sysfs_emit (buf,"%d\n" , value); }
@@ -538,13 +538,18 @@ static DEVICE_ATTR_RO(runtime_active_kids);static ssize_t runtime_enabled_show (struct device *dev,struct device_attribute *attr,char *buf) { -if (dev->power.disable_depth && (dev->power.runtime_auto == false)) -return sysfs_emit (buf,"disabled & forbidden\n" ); -if (dev->power.disable_depth) -return sysfs_emit (buf,"disabled\n" ); -if (dev->power.runtime_auto == false) -return sysfs_emit (buf,"forbidden\n" ); -return sysfs_emit (buf,"enabled\n" ); +const char *type; + +if (dev->power.disable_depth && !dev->power.runtime_auto) + type ="disabled & forbidden" ; +else if (dev->power.disable_depth) + type ="disabled" ; +else if (!dev->power.runtime_auto) + type ="forbidden" ; +else + type ="enabled" ; + +return sysfs_emit (buf,"%s\n" , type); }static DEVICE_ATTR_RO (runtime_enabled);
Signature · 1 line
2.26.0
kernel test robot
build botRe: [PATCH 2/4] drivers core: Remove strcat uses around sysfs_emit and neaten
I love your patch! Yet something to improve:
Hi Joe,
I love your patch! Yet something to improve:
[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on pm/linux-next linus/master v5.9-rc4 next-20200903] [cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 4024823563d05bbe880885c9987d14a7130801da config: s390-randconfig-s031-20200908 (attached as .config) compiler: s390-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-191-g10164920-dirty
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/base/memory.c: In function 'phys_index_show':
drivers/base/memory.c:122:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
122 | return sysfs_emit(buf, "%08lx\n", phys_index);
| ^~~~~~~~~~
| sysfs_init
drivers/base/memory.c: In function 'print_allowed_zone':
>> drivers/base/memory.c:317:9: error: implicit declaration of function 'sysfs_emit_at'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
317 | return sysfs_emit_at(buf, len, " %s", zone->name);
| ^~~~~~~~~~~~~
| sysfs_initcc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/a8789a23413de463f5e591d57748493242aa4be4
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 git checkout a8789a23413de463f5e591d57748493242aa4be4
vim +317 drivers/base/memory.c
306
307 #ifdef CONFIG_MEMORY_HOTREMOVE
308 static int print_allowed_zone(char *buf, int len, int nid,
309 unsigned long start_pfn, unsigned long nr_pages,
310 int online_type, struct zone *default_zone)
311 {
312 struct zone *zone;
313
314 zone = zone_for_pfn_range(online_type, nid, start_pfn, nr_pages);
315 if (zone == default_zone)
316 return 0;
> 317 return sysfs_emit_at(buf, len, " %s", zone->name);
318 }
319
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Greg Kroah-Hartman
maintainerRe: [PATCH 2/4] drivers core: Remove strcat uses around sysfs_emit and neaten
In reply to Joe PerchesQuoted 32 lines · Joe Perches
strcat is no longer necessary for
sysfs_emitandsysfs_emit_atuses.Convert the strcat uses to
sysfs_emitcalls and neaten other block uses of direct returns to use an intermediate const char *.Signed-off-by Joe Perches <[email protected]>--- drivers/base/cacheinfo.c | 26 ++++++++++++++------- drivers/base/core.c | 10 ++++---- drivers/base/memory.c | 47 ++++++++++++++++++-------------------- drivers/base/power/sysfs.c | 23 +++++++++++-------- 4 files changed, 59 insertions(+), 47 deletions(-)drivers/base/cacheinfo.c +5
-2@@ -404,17 +404,23 @@ static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf) { struct cacheinfo *this_leaf = dev_get_drvdata(dev); +const char *type =NULL ;switch (this_leaf->type) {case CACHE_TYPE_DATA : -return sysfs_emit (buf,"Data\n" ); + type ="Data" ; +break ;case CACHE_TYPE_INST : -return sysfs_emit (buf,"Instruction\n" ); + type ="Instruction" ; +break ;
drivers/base/cacheinfo.c static ssize_t type_show(struct device *dev, · line 424
Quoted 10 lines
drivers/base/cacheinfo.c +4
-1case CACHE_TYPE_UNIFIED : -return sysfs_emit (buf,"Unified\n" ); + type ="Unified" ; +break ;default :return -EINVAL ; } + +return sysfs_emit (buf,"%s\n" , type); }
This function is now longer, with an assignment that is not needed (type=NULL), so why make this "cleanup"?
drivers/base/cacheinfo.c static ssize_t allocation_policy_show(struct device *dev, · line 431
Quoted 8 lines
drivers/base/cacheinfo.c +1
-1static ssize_t allocation_policy_show(struct device *dev,@@ -422,15 +428,19 @@ static ssize_t allocation_policy_show(struct device *dev, {struct cacheinfo *this_leaf =dev_get_drvdata (dev);unsigned int ci_attr = this_leaf->attributes; -int n =0 ; +const char *type =NULL ;
It's a policy, not a type.
Quoted 7 lines
drivers/base/cacheinfo.c +2
-2if ((ci_attr &CACHE_READ_ALLOCATE ) && (ci_attr &CACHE_WRITE_ALLOCATE )) - n =sysfs_emit (buf,"ReadWriteAllocate\n" ); + type ="ReadWriteAllocate" ;else if (ci_attr &CACHE_READ_ALLOCATE ) - n =sysfs_emit (buf,"ReadAllocate\n" ); + type ="ReadAllocate" ;
drivers/base/cacheinfo.c static ssize_t allocation_policy_show(struct device *dev, · line 444
Quoted 10 lines
drivers/base/cacheinfo.c +6
-2else if (ci_attr &CACHE_WRITE_ALLOCATE ) - n =sysfs_emit (buf,"WriteAllocate\n" ); -return n; + type ="WriteAllocate" ; + +if (!type) +return 0 ; + +return sysfs_emit (buf,"%s\n" , type); }
Overall, this is a bit nicer, thanks.
Quoted 15 lines
drivers/base/cacheinfo.c +0
-0static ssize_t write_policy_show(struct device *dev,drivers/base/core.c +1
-2@@ -267,16 +267,16 @@ static ssize_t auto_remove_on_show(struct device *dev, struct device_attribute *attr, char *buf) { struct device_link *link = to_devlink(dev); -char *str; +char *type;if (link->flags &DL_FLAG_AUTOREMOVE_SUPPLIER ) - str ="supplier unbind" ;
drivers/base/core.c static ssize_t auto_remove_on_show(struct device *dev, · line 279
Quoted 10 lines
drivers/base/core.c +4
-3+ type ="supplier unbind" ; else if (link->flags & DL_FLAG_AUTOREMOVE_CONSUMER) - str ="consumer unbind" ; + type ="consumer unbind" ; else - str ="never" ; + type ="never" ; -return sysfs_emit (buf,"%s\n" , str); +return sysfs_emit (buf,"%s\n" , type);
This isn't a "type", it is just a string :(
Quoted 31 lines
drivers/base/core.c +0
-0}static DEVICE_ATTR_RO (auto_remove_on);drivers/base/memory.c +4
-4@@ -139,7 +139,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) {struct memory_block *mem =to_memory_block (dev); -ssize_t len =0 ; +const char *type;/* * We can probably put these states in a nice little array @@ -147,22 +147,20 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,*/ switch (mem->state) {case MEM_ONLINE : - len =sysfs_emit (buf,"online\n" ); + type ="online" ;break ;case MEM_OFFLINE : - len =sysfs_emit (buf,"offline\n" ); + type ="offline" ;break ;case MEM_GOING_OFFLINE : - len =sysfs_emit (buf,"going-offline\n" ); + type ="going-offline" ;break ;
drivers/base/memory.c static ssize_t state_show(struct device *dev, struct device_attribute *attr, · line 163
Quoted 10 lines
drivers/base/memory.c +2
-4default : - len =sysfs_emit (buf,"ERROR-UNKNOWN-%ld\n" , - mem->state);WARN_ON (1 ); -break ; +return sysfs_emit (buf,"ERROR-UNKNOWN-%ld\n" , mem->state); } -return len; +return sysfs_emit (buf,"%s\n" , type);
Again, not a type, it's a state. And you did not merge all sysfs_emit() calls into one here, so it's messier now, don't you think?
drivers/base/memory.c static ssize_t phys_device_show(struct device *dev, · line 310
Quoted 13 lines
drivers/base/memory.c +3
-3}int memory_notify (unsigned long val,void *v)@@ -307,17 +305,16 @@ static ssize_t phys_device_show(struct device *dev, }#ifdef CONFIG_MEMORY_HOTREMOVE -static void print_allowed_zone (char *buf,int nid,unsigned long start_pfn, -unsigned long nr_pages,int online_type, -struct zone *default_zone) +static int print_allowed_zone (char *buf,int len,int nid, +unsigned long start_pfn,unsigned long nr_pages, +int online_type,struct zone *default_zone)
Unrelated change :(
drivers/base/memory.c static ssize_t phys_device_show(struct device *dev, · line 318
Quoted 12 lines
drivers/base/memory.c +3
-4{struct zone *zone; zone =zone_for_pfn_range (online_type, nid, start_pfn, nr_pages); -if (zone != default_zone) { -strcat (buf," " ); -strcat (buf, zone->name); - } +if (zone == default_zone) +return 0 ; +return sysfs_emit_at (buf, len," %s" , zone->name); }
Nicer looking, thanks.
Quoted 31 lines
drivers/base/memory.c +4
-7static ssize_t valid_zones_show(struct device *dev,@@ -327,6 +324,7 @@ static ssize_t valid_zones_show(struct device *dev,unsigned long start_pfn =section_nr_to_pfn (mem->start_section_nr);unsigned long nr_pages =PAGES_PER_SECTION * sections_per_block;struct zone *default_zone; +int len =0 ;int nid;/* @@ -341,24 +339,23 @@ static ssize_t valid_zones_show(struct device *dev, default_zone =test_pages_in_a_zone (start_pfn, start_pfn + nr_pages);if (!default_zone) -return sysfs_emit (buf,"none\n" ); -strcat (buf, default_zone->name); +return sysfs_emit (buf,"%s\n" ,"none" ); + len +=sysfs_emit_at (buf, len,"%s" , default_zone->name); goto out; } nid = mem->nid; default_zone =zone_for_pfn_range (MMOP_ONLINE , nid, start_pfn, nr_pages); -strcat (buf, default_zone->name); -print_allowed_zone (buf, nid, start_pfn, nr_pages,MMOP_ONLINE_KERNEL , - default_zone); -print_allowed_zone (buf, nid, start_pfn, nr_pages,MMOP_ONLINE_MOVABLE , - default_zone); + len +=sysfs_emit_at (buf, len,"%s" , default_zone->name);
drivers/base/memory.c static ssize_t valid_zones_show(struct device *dev, · line 358
Quoted 10 lines
drivers/base/memory.c +6
-3+ len +=print_allowed_zone (buf, len, nid, start_pfn, nr_pages, +MMOP_ONLINE_KERNEL , default_zone); + len +=print_allowed_zone (buf, len, nid, start_pfn, nr_pages, +MMOP_ONLINE_MOVABLE , default_zone); out: -strcat (buf,"\n" ); - -return strlen (buf); + len +=sysfs_emit_at (buf, len,"%s" ,"\n" ); +return len;
This is better.
Quoted 9 lines
drivers/base/memory.c +0
-0}static DEVICE_ATTR_RO (valid_zones);#endif drivers/base/power/sysfs.c +0
-0@@ -255,9 +255,9 @@ static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev,s32 value =dev_pm_qos_get_user_latency_tolerance (dev);
drivers/base/power/sysfs.c static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev, · line 263
Quoted 10 lines
drivers/base/power/sysfs.c +2
-2if (value <0 ) -return sysfs_emit (buf,"auto\n" ); +return sysfs_emit (buf,"%s\n" ,"auto" );if (value ==PM_QOS_LATENCY_ANY ) -return sysfs_emit (buf,"any\n" ); +return sysfs_emit (buf,"%s\n" ,"any" );return sysfs_emit (buf,"%d\n" , value); }
Unrelated change :(
Quoted 13 lines
drivers/base/power/sysfs.c +2
-7@@ -538,13 +538,18 @@ static DEVICE_ATTR_RO(runtime_active_kids);static ssize_t runtime_enabled_show (struct device *dev,struct device_attribute *attr,char *buf) { -if (dev->power.disable_depth && (dev->power.runtime_auto == false)) -return sysfs_emit (buf,"disabled & forbidden\n" ); -if (dev->power.disable_depth) -return sysfs_emit (buf,"disabled\n" ); -if (dev->power.runtime_auto == false) -return sysfs_emit (buf,"forbidden\n" ); -return sysfs_emit (buf,"enabled\n" ); +const char *type; +
drivers/base/power/sysfs.c static DEVICE_ATTR_RO(runtime_active_kids); · line 552
Quoted 10 lines
drivers/base/power/sysfs.c +10
-0+if (dev->power.disable_depth && !dev->power.runtime_auto) + type ="disabled & forbidden" ; +else if (dev->power.disable_depth) + type ="disabled" ; +else if (!dev->power.runtime_auto) + type ="forbidden" ; +else + type ="enabled" ; + +return sysfs_emit (buf,"%s\n" , type);
It's not a type :(
thanks,
greg k-h
Re: [PATCH 2/4] drivers core: Remove strcat uses around sysfs_emit and neaten
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Joe Perches
strcat is no longer necessary for
sysfs_emitandsysfs_emit_atuses.Convert the strcat uses to
sysfs_emitcalls and neaten other block uses of direct returns to use an intermediate const char *.
[]
Quoted 2 lines
This function is now longer, with an assignment that is not needed (type=NULL), so why make this "cleanup"?
It's smaller object code.
[]
Quoted 2 lines
Quoted 1 line
Again, not a type, it's a state. And you did not merge all
sysfs_emit()calls into one here, so it's messier now, don't you think?
You can't because the default type uses an argument and not a fixed string. I don't think it's messier, no.
Quoted 4 lines
Quoted 4 lines
int
memory_notify(unsigned long val, void *v)(quoted diff) +0
-0@@ -307,17 +305,16 @@ static ssize_t phys_device_show(struct device *dev, }
Quoted 9 lines
drivers/base/memory.c static ssize_t phys_device_show(struct device *dev, · line 310
Quoted 7 lines
drivers/base/memory.c +3
-3#ifdef CONFIG_MEMORY_HOTREMOVE -static void print_allowed_zone (char *buf,int nid,unsigned long start_pfn, -unsigned long nr_pages,int online_type, -struct zone *default_zone) +static int print_allowed_zone (char *buf,int len,int nid, +unsigned long start_pfn,unsigned long nr_pages, +int online_type,struct zone *default_zone)Unrelated change :(
No it's not, it's outputting to buf so it
needs len to output to appropriate spot to
be able to use sysfs_emit_at.
Quoted 11 lines
drivers/base/memory.c static ssize_t phys_device_show(struct device *dev, · line 317
Quoted 11 lines
drivers/base/memory.c +3
-4{struct zone *zone; zone =zone_for_pfn_range (online_type, nid, start_pfn, nr_pages); -if (zone != default_zone) { -strcat (buf," " ); -strcat (buf, zone->name); - } +if (zone == default_zone) +return 0 ; +return sysfs_emit_at (buf, len," %s" , zone->name);
here.
Quoted 3 lines
[]
This is better.
All of it is better. <smile>
Quoted 1 line
drivers/base/power/sysfs.c
Quoted 1 line
drivers/base/power/sysfs.c +0
-0
[]
Quoted 10 lines
Quoted 10 lines
drivers/base/power/sysfs.c +2
-2@@ -255,9 +255,9 @@ static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev,s32 value =dev_pm_qos_get_user_latency_tolerance (dev);if (value <0 ) -return sysfs_emit (buf,"auto\n" ); +return sysfs_emit (buf,"%s\n" ,"auto" );if (value ==PM_QOS_LATENCY_ANY ) -return sysfs_emit (buf,"any\n" ); +return sysfs_emit (buf,"%s\n" ,"any" );
Quoted 4 lines
drivers/base/power/sysfs.c static ssize_t pm_qos_latency_tolerance_us_show(struct device *dev, · line 263
Quoted 2 lines
drivers/base/power/sysfs.c +0
-0return sysfs_emit (buf,"%d\n" , value); }Unrelated change :(
Again, no it's not unrelated, it's consistent.
PATCH 3/4 drivers core: Reindent a couple uses around sysfs_emit
In reply to Joe PerchesJust a couple of whitespace realignment to open parenthesis for multi-line statements.
--- drivers/base/node.c | 4 ++-- drivers/base/power/sysfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/base/node.c +2 -2
@@ -386,9 +386,9 @@ static ssize_t node_read_meminfo(struct device *dev, nid,K (i.freeram), nid,K (i.totalram - i.freeram), nid,K (node_page_state (pgdat,NR_ACTIVE_ANON ) + -node_page_state (pgdat,NR_ACTIVE_FILE )), +node_page_state (pgdat,NR_ACTIVE_FILE )), nid,K (node_page_state (pgdat,NR_INACTIVE_ANON ) + -node_page_state (pgdat,NR_INACTIVE_FILE )), +node_page_state (pgdat,NR_INACTIVE_FILE )), nid,K (node_page_state (pgdat,NR_ACTIVE_ANON )), nid,K (node_page_state (pgdat,NR_INACTIVE_ANON )), nid, K(node_page_state(pgdat, NR_ACTIVE_FILE)),
drivers/base/power/sysfs.c +1 -1
@@ -102,7 +102,7 @@ static ssize_t control_show(struct device *dev, struct device_attribute *attr, char *buf) {return sysfs_emit (buf,"%s\n" , - dev->power.runtime_auto ? ctrl_auto : ctrl_on); + dev->power.runtime_auto ? ctrl_auto : ctrl_on); } static ssize_t control_store(struct device * dev, struct device_attribute *attr,
Signature · 1 line
2.26.0
PATCH 4/4 drivers core: Miscellaneous changes for sysfs_emit
In reply to Joe PerchesChange a few additional instances that could use sysfs_emit that the coccinelle script could not convert.
--- drivers/base/class.c | 2 +- drivers/base/cpu.c | 18 +++++++++--------- drivers/base/node.c | 15 +++------------ drivers/base/platform.c | 4 +--- 4 files changed, 14 insertions(+), 25 deletions(-)
drivers/base/class.c +1 -1
@@ -478,7 +478,7 @@ ssize_t show_class_attr_string(struct class *class,struct class_attribute_string *cs; cs = container_of(attr, struct class_attribute_string, attr); -return snprintf (buf,PAGE_SIZE ,"%s\n" , cs->str); +return sysfs_emit (buf,"%s\n" , cs->str); }EXPORT_SYMBOL_GPL (show_class_attr_string);
drivers/base/cpu.c +9 -9
@@ -241,30 +241,30 @@ unsigned int total_cpus;static ssize_t print_cpus_offline (struct device *dev,struct device_attribute *attr,char *buf) { -int n =0 , len =PAGE_SIZE -2 ; +int len =0 ;cpumask_var_t offline;/* display offline cpus < nr_cpu_ids */ if (!alloc_cpumask_var (&offline,GFP_KERNEL ))return -ENOMEM ;cpumask_andnot (offline, cpu_possible_mask, cpu_online_mask); - n =scnprintf (buf, len,"%*pbl" ,cpumask_pr_args (offline)); + len +=sysfs_emit_at (buf, len,"%*pbl" ,cpumask_pr_args (offline));free_cpumask_var (offline);/* display offline cpus >= nr_cpu_ids */ if (total_cpus && nr_cpu_ids < total_cpus) { -if (n && n < len) - buf[n++] =',' ; + len +=sysfs_emit_at (buf, len,"%s" ,"," );if (nr_cpu_ids == total_cpus-1 ) - n +=scnprintf (&buf[n], len - n,"%u" , nr_cpu_ids); + len +=sysfs_emit_at (buf, len,"%u" , nr_cpu_ids);else - n +=scnprintf (&buf[n], len - n,"%u-%d" , - nr_cpu_ids, total_cpus-1 ); + len +=sysfs_emit_at (buf, len,"%u-%d" , + nr_cpu_ids, total_cpus-1 ); } - n +=scnprintf (&buf[n], len - n,"\n" ); -return n; + len +=sysfs_emit_at (buf, len,"%s" ,"\n" ); + +return len; } static DEVICE_ATTR(offline, 0444, print_cpus_offline, NULL);
drivers/base/node.c +3 -12
@@ -945,17 +945,6 @@ void unregister_one_node(int nid)* node states attributes */ -static ssize_t print_nodes_state (enum node_states state,char *buf) -{ -int n; - - n =scnprintf (buf,PAGE_SIZE -1 ,"%*pbl" , -nodemask_pr_args (&node_states[state])); - buf[n++] ='\n' ; - buf[n] ='\0' ; -return n; -} -struct node_attr {struct device_attribute attr;enum node_states state;
@@ -965,7 +954,9 @@ static ssize_t show_node_state(struct device *dev, struct device_attribute *attr, char *buf) { struct node_attr *na = container_of(attr, struct node_attr, attr); -return print_nodes_state (na->state, buf); + +return sysfs_emit (buf,"%*pbl\n" , +nodemask_pr_args (&node_states[na->state])); }#define _NODE_ATTR (name, state) \
drivers/base/platform.c +1 -3
@@ -1023,9 +1023,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a,if (len != -ENODEV )return len; - len =snprintf (buf,PAGE_SIZE ,"platform:%s\n" , pdev->name); - -return (len >=PAGE_SIZE ) ? (PAGE_SIZE -1 ) : len; +return sysfs_emit (buf,"platform:%s\n" , pdev->name); }static DEVICE_ATTR_RO (modalias);
Signature · 1 line
2.26.0
kernel test robot
build botRe: [PATCH 4/4] drivers core: Miscellaneous changes for sysfs_emit
I love your patch! Yet something to improve:
Hi Joe,
I love your patch! Yet something to improve:
[auto build test ERROR on driver-core/driver-core-testing]
[also build test ERROR on pm/linux-next linus/master v5.9-rc4 next-20200903] [cannot apply to linux/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git 4024823563d05bbe880885c9987d14a7130801da config: h8300-randconfig-r005-20200908 (attached as .config) compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=h8300
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/base/class.c: In function 'show_class_attr_string':
>> drivers/base/class.c:481:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
481 | return sysfs_emit(buf, "%s\n", cs->str);
| ^~~~~~~~~~
| sysfs_init cc1: some warnings being treated as errors
--
drivers/base/cpu.c: In function 'print_cpus_kernel_max':
drivers/base/cpu.c:234:9: error: implicit declaration of function 'sysfs_emit'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
234 | return sysfs_emit(buf, "%d\n", NR_CPUS - 1);
| ^~~~~~~~~~
| sysfs_init
drivers/base/cpu.c: In function 'print_cpus_offline':
>> drivers/base/cpu.c:251:9: error: implicit declaration of function 'sysfs_emit_at'; did you mean 'sysfs_init'? [-Werror=implicit-function-declaration]
251 | len += sysfs_emit_at(buf, len, "%*pbl", cpumask_pr_args(offline));
| ^~~~~~~~~~~~~
| sysfs_initcc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/0c3c0f3efcf691e49eaf0745d0b86f5ab991d989
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Joe-Perches/drivers-core-Use-sysfs_emit-functions/20200908-021333 git checkout 0c3c0f3efcf691e49eaf0745d0b86f5ab991d989
vim +481 drivers/base/class.c
474
475 ssize_t show_class_attr_string(struct class *class,
476 struct class_attribute *attr, char *buf)
477 {
478 struct class_attribute_string *cs;
479
480 cs = container_of(attr, struct class_attribute_string, attr);
> 481 return sysfs_emit(buf, "%s\n", cs->str);
482 }
483
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[PATCH 5/4] drivers core: Convert class uses of sprintf to sysfs_emit
In reply to Joe PerchesUse the sysfs_emit API.
--- drivers/base/devcoredump.c | 2 +- drivers/base/firmware_loader/fallback.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/devcoredump.c +1 -1
@@ -123,7 +123,7 @@ static int devcd_free(struct device *dev, void *data)static ssize_t disabled_show (struct class *class,struct class_attribute *attr,char *buf) { -return sprintf (buf,"%d\n" , devcd_disabled); +return sysfs_emit (buf,"%d\n" , devcd_disabled); } static ssize_t disabled_store(struct class *class, struct class_attribute *attr,
drivers/base/firmware_loader/fallback.c +1 -1
@@ -124,7 +124,7 @@ void kill_pending_fw_fallback_reqs(bool only_kill_custom)static ssize_t timeout_show (struct class *class,struct class_attribute *attr,char *buf) { -return sprintf (buf,"%d\n" ,__firmware_loading_timeout ()); +return sysfs_emit (buf,"%d\n" ,__firmware_loading_timeout ()); }/**
Signature · 1 line
2.26.0