Skip to content

Commit 35aa062

Browse files
ye xingchensre
authored andcommitted
power: supply: use sysfs_emit() instead of scnprintf() for sysfs show()
As documented in Documentation/filesystems/sysfs.rst the sysfs show() function should use sysfs_emit() or sysfs_emit_at() to format the userspace return value. This replaces all instances of scnprintf() with sysfs_emit() in the power-supply subsystem. Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn> [reword commit message] Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 1b929c0 commit 35aa062

7 files changed

Lines changed: 22 additions & 27 deletions

File tree

drivers/power/supply/ab8500_fg.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,7 @@ static ssize_t ab8505_powercut_flagtime_read(struct device *dev,
25942594
goto fail;
25952595
}
25962596

2597-
return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7F));
2597+
return sysfs_emit(buf, "%d\n", (reg_value & 0x7F));
25982598

25992599
fail:
26002600
return ret;
@@ -2644,7 +2644,7 @@ static ssize_t ab8505_powercut_maxtime_read(struct device *dev,
26442644
goto fail;
26452645
}
26462646

2647-
return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7F));
2647+
return sysfs_emit(buf, "%d\n", (reg_value & 0x7F));
26482648

26492649
fail:
26502650
return ret;
@@ -2695,7 +2695,7 @@ static ssize_t ab8505_powercut_restart_read(struct device *dev,
26952695
goto fail;
26962696
}
26972697

2698-
return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0xF));
2698+
return sysfs_emit(buf, "%d\n", (reg_value & 0xF));
26992699

27002700
fail:
27012701
return ret;
@@ -2746,7 +2746,7 @@ static ssize_t ab8505_powercut_timer_read(struct device *dev,
27462746
goto fail;
27472747
}
27482748

2749-
return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7F));
2749+
return sysfs_emit(buf, "%d\n", (reg_value & 0x7F));
27502750

27512751
fail:
27522752
return ret;
@@ -2769,7 +2769,7 @@ static ssize_t ab8505_powercut_restart_counter_read(struct device *dev,
27692769
goto fail;
27702770
}
27712771

2772-
return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0xF0) >> 4);
2772+
return sysfs_emit(buf, "%d\n", (reg_value & 0xF0) >> 4);
27732773

27742774
fail:
27752775
return ret;
@@ -2790,7 +2790,7 @@ static ssize_t ab8505_powercut_read(struct device *dev,
27902790
if (ret < 0)
27912791
goto fail;
27922792

2793-
return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x1));
2793+
return sysfs_emit(buf, "%d\n", (reg_value & 0x1));
27942794

27952795
fail:
27962796
return ret;
@@ -2841,7 +2841,7 @@ static ssize_t ab8505_powercut_flag_read(struct device *dev,
28412841
goto fail;
28422842
}
28432843

2844-
return scnprintf(buf, PAGE_SIZE, "%d\n", ((reg_value & 0x10) >> 4));
2844+
return sysfs_emit(buf, "%d\n", ((reg_value & 0x10) >> 4));
28452845

28462846
fail:
28472847
return ret;
@@ -2864,7 +2864,7 @@ static ssize_t ab8505_powercut_debounce_read(struct device *dev,
28642864
goto fail;
28652865
}
28662866

2867-
return scnprintf(buf, PAGE_SIZE, "%d\n", (reg_value & 0x7));
2867+
return sysfs_emit(buf, "%d\n", (reg_value & 0x7));
28682868

28692869
fail:
28702870
return ret;
@@ -2914,7 +2914,7 @@ static ssize_t ab8505_powercut_enable_status_read(struct device *dev,
29142914
goto fail;
29152915
}
29162916

2917-
return scnprintf(buf, PAGE_SIZE, "%d\n", ((reg_value & 0x20) >> 5));
2917+
return sysfs_emit(buf, "%d\n", ((reg_value & 0x20) >> 5));
29182918

29192919
fail:
29202920
return ret;

drivers/power/supply/bq24190_charger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static ssize_t bq24190_sysfs_show(struct device *dev,
463463
if (ret)
464464
count = ret;
465465
else
466-
count = scnprintf(buf, PAGE_SIZE, "%hhx\n", v);
466+
count = sysfs_emit(buf, "%hhx\n", v);
467467

468468
pm_runtime_mark_last_busy(bdi->dev);
469469
pm_runtime_put_autosuspend(bdi->dev);

drivers/power/supply/bq24257_charger.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,7 @@ static ssize_t bq24257_show_ovp_voltage(struct device *dev,
767767
struct power_supply *psy = dev_get_drvdata(dev);
768768
struct bq24257_device *bq = power_supply_get_drvdata(psy);
769769

770-
return scnprintf(buf, PAGE_SIZE, "%u\n",
771-
bq24257_vovp_map[bq->init_data.vovp]);
770+
return sysfs_emit(buf, "%u\n", bq24257_vovp_map[bq->init_data.vovp]);
772771
}
773772

774773
static ssize_t bq24257_show_in_dpm_voltage(struct device *dev,
@@ -778,8 +777,7 @@ static ssize_t bq24257_show_in_dpm_voltage(struct device *dev,
778777
struct power_supply *psy = dev_get_drvdata(dev);
779778
struct bq24257_device *bq = power_supply_get_drvdata(psy);
780779

781-
return scnprintf(buf, PAGE_SIZE, "%u\n",
782-
bq24257_vindpm_map[bq->init_data.vindpm]);
780+
return sysfs_emit(buf, "%u\n", bq24257_vindpm_map[bq->init_data.vindpm]);
783781
}
784782

785783
static ssize_t bq24257_sysfs_show_enable(struct device *dev,
@@ -800,7 +798,7 @@ static ssize_t bq24257_sysfs_show_enable(struct device *dev,
800798
if (ret < 0)
801799
return ret;
802800

803-
return scnprintf(buf, PAGE_SIZE, "%d\n", ret);
801+
return sysfs_emit(buf, "%d\n", ret);
804802
}
805803

806804
static ssize_t bq24257_sysfs_set_enable(struct device *dev,

drivers/power/supply/lp8788-charger.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ static ssize_t lp8788_show_charger_status(struct device *dev,
602602
lp8788_read_byte(pchg->lp, LP8788_CHG_STATUS, &data);
603603
state = (data & LP8788_CHG_STATE_M) >> LP8788_CHG_STATE_S;
604604

605-
return scnprintf(buf, PAGE_SIZE, "%s\n", desc[state]);
605+
return sysfs_emit(buf, "%s\n", desc[state]);
606606
}
607607

608608
static ssize_t lp8788_show_eoc_time(struct device *dev,
@@ -618,8 +618,7 @@ static ssize_t lp8788_show_eoc_time(struct device *dev,
618618
lp8788_read_byte(pchg->lp, LP8788_CHG_EOC, &val);
619619
val = (val & LP8788_CHG_EOC_TIME_M) >> LP8788_CHG_EOC_TIME_S;
620620

621-
return scnprintf(buf, PAGE_SIZE, "End Of Charge Time: %s\n",
622-
stime[val]);
621+
return sysfs_emit(buf, "End Of Charge Time: %s\n", stime[val]);
623622
}
624623

625624
static ssize_t lp8788_show_eoc_level(struct device *dev,
@@ -642,7 +641,7 @@ static ssize_t lp8788_show_eoc_level(struct device *dev,
642641
val = (val & LP8788_CHG_EOC_LEVEL_M) >> LP8788_CHG_EOC_LEVEL_S;
643642
level = mode ? abs_level[val] : relative_level[val];
644643

645-
return scnprintf(buf, PAGE_SIZE, "End Of Charge Level: %s\n", level);
644+
return sysfs_emit(buf, "End Of Charge Level: %s\n", level);
646645
}
647646

648647
static DEVICE_ATTR(charger_status, S_IRUSR, lp8788_show_charger_status, NULL);

drivers/power/supply/max14577_charger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ static ssize_t show_fast_charge_timer(struct device *dev,
532532
break;
533533
}
534534

535-
return scnprintf(buf, PAGE_SIZE, "%u\n", val);
535+
return sysfs_emit(buf, "%u\n", val);
536536
}
537537

538538
static ssize_t store_fast_charge_timer(struct device *dev,

drivers/power/supply/max77693_charger.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static ssize_t fast_charge_timer_show(struct device *dev,
296296
break;
297297
}
298298

299-
return scnprintf(buf, PAGE_SIZE, "%u\n", val);
299+
return sysfs_emit(buf, "%u\n", val);
300300
}
301301

302302
static int max77693_set_fast_charge_timer(struct max77693_charger *chg,
@@ -357,7 +357,7 @@ static ssize_t top_off_threshold_current_show(struct device *dev,
357357
else
358358
val = data * 50000;
359359

360-
return scnprintf(buf, PAGE_SIZE, "%u\n", val);
360+
return sysfs_emit(buf, "%u\n", val);
361361
}
362362

363363
static int max77693_set_top_off_threshold_current(struct max77693_charger *chg,
@@ -405,7 +405,7 @@ static ssize_t top_off_timer_show(struct device *dev,
405405

406406
val = data * 10;
407407

408-
return scnprintf(buf, PAGE_SIZE, "%u\n", val);
408+
return sysfs_emit(buf, "%u\n", val);
409409
}
410410

411411
static int max77693_set_top_off_timer(struct max77693_charger *chg,

drivers/power/supply/twl4030_charger.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,9 @@ twl4030_bci_mode_show(struct device *dev,
726726

727727
for (i = 0; i < ARRAY_SIZE(modes); i++)
728728
if (mode == i)
729-
len += scnprintf(buf+len, PAGE_SIZE-len,
730-
"[%s] ", modes[i]);
729+
len += sysfs_emit_at(buf, len, "[%s] ", modes[i]);
731730
else
732-
len += scnprintf(buf+len, PAGE_SIZE-len,
733-
"%s ", modes[i]);
731+
len += sysfs_emit_at(buf, len, "%s ", modes[i]);
734732
buf[len-1] = '\n';
735733
return len;
736734
}

0 commit comments

Comments
 (0)