Skip to content

Commit 17daae7

Browse files
committed
ALSA: hda: Replace sprintf() with sysfs_emit()
For sysfs outputs, it's safer to use a new helper, sysfs_emit(), instead of the raw sprintf() & co. This patch replaces those usages straightforwardly with new helpers, sysfs_emit() and sysfs_emit_at(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 01043e3 commit 17daae7

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

sound/hda/hdac_sysfs.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static ssize_t type##_show(struct device *dev, \
2222
char *buf) \
2323
{ \
2424
struct hdac_device *codec = dev_to_hdac_dev(dev); \
25-
return sprintf(buf, "0x%x\n", codec->type); \
25+
return sysfs_emit(buf, "0x%x\n", codec->type); \
2626
} \
2727
static DEVICE_ATTR_RO(type)
2828

@@ -32,8 +32,8 @@ static ssize_t type##_show(struct device *dev, \
3232
char *buf) \
3333
{ \
3434
struct hdac_device *codec = dev_to_hdac_dev(dev); \
35-
return sprintf(buf, "%s\n", \
36-
codec->type ? codec->type : ""); \
35+
return sysfs_emit(buf, "%s\n", \
36+
codec->type ? codec->type : ""); \
3737
} \
3838
static DEVICE_ATTR_RO(type)
3939

@@ -161,16 +161,16 @@ static struct kobj_type widget_ktype = {
161161
static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid,
162162
struct widget_attribute *attr, char *buf)
163163
{
164-
return sprintf(buf, "0x%08x\n", get_wcaps(codec, nid));
164+
return sysfs_emit(buf, "0x%08x\n", get_wcaps(codec, nid));
165165
}
166166

167167
static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid,
168168
struct widget_attribute *attr, char *buf)
169169
{
170170
if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
171171
return 0;
172-
return sprintf(buf, "0x%08x\n",
173-
snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP));
172+
return sysfs_emit(buf, "0x%08x\n",
173+
snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP));
174174
}
175175

176176
static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid,
@@ -182,7 +182,7 @@ static ssize_t pin_cfg_show(struct hdac_device *codec, hda_nid_t nid,
182182
return 0;
183183
if (snd_hdac_read(codec, nid, AC_VERB_GET_CONFIG_DEFAULT, 0, &val))
184184
return 0;
185-
return sprintf(buf, "0x%08x\n", val);
185+
return sysfs_emit(buf, "0x%08x\n", val);
186186
}
187187

188188
static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid)
@@ -203,51 +203,51 @@ static ssize_t pcm_caps_show(struct hdac_device *codec, hda_nid_t nid,
203203
{
204204
if (!has_pcm_cap(codec, nid))
205205
return 0;
206-
return sprintf(buf, "0x%08x\n",
207-
snd_hdac_read_parm(codec, nid, AC_PAR_PCM));
206+
return sysfs_emit(buf, "0x%08x\n",
207+
snd_hdac_read_parm(codec, nid, AC_PAR_PCM));
208208
}
209209

210210
static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid,
211211
struct widget_attribute *attr, char *buf)
212212
{
213213
if (!has_pcm_cap(codec, nid))
214214
return 0;
215-
return sprintf(buf, "0x%08x\n",
216-
snd_hdac_read_parm(codec, nid, AC_PAR_STREAM));
215+
return sysfs_emit(buf, "0x%08x\n",
216+
snd_hdac_read_parm(codec, nid, AC_PAR_STREAM));
217217
}
218218

219219
static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid,
220220
struct widget_attribute *attr, char *buf)
221221
{
222222
if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
223223
return 0;
224-
return sprintf(buf, "0x%08x\n",
225-
snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP));
224+
return sysfs_emit(buf, "0x%08x\n",
225+
snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP));
226226
}
227227

228228
static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid,
229229
struct widget_attribute *attr, char *buf)
230230
{
231231
if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
232232
return 0;
233-
return sprintf(buf, "0x%08x\n",
234-
snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP));
233+
return sysfs_emit(buf, "0x%08x\n",
234+
snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP));
235235
}
236236

237237
static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid,
238238
struct widget_attribute *attr, char *buf)
239239
{
240240
if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER))
241241
return 0;
242-
return sprintf(buf, "0x%08x\n",
243-
snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE));
242+
return sysfs_emit(buf, "0x%08x\n",
243+
snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE));
244244
}
245245

246246
static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid,
247247
struct widget_attribute *attr, char *buf)
248248
{
249-
return sprintf(buf, "0x%08x\n",
250-
snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP));
249+
return sysfs_emit(buf, "0x%08x\n",
250+
snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP));
251251
}
252252

253253
static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid,
@@ -261,8 +261,8 @@ static ssize_t connections_show(struct hdac_device *codec, hda_nid_t nid,
261261
if (nconns <= 0)
262262
return nconns;
263263
for (i = 0; i < nconns; i++)
264-
ret += sprintf(buf + ret, "%s0x%02x", i ? " " : "", list[i]);
265-
ret += sprintf(buf + ret, "\n");
264+
ret += sysfs_emit_at(buf, ret, "%s0x%02x", i ? " " : "", list[i]);
265+
ret += sysfs_emit_at(buf, ret, "\n");
266266
return ret;
267267
}
268268

sound/pci/hda/hda_sysfs.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static ssize_t power_on_acct_show(struct device *dev,
3333
{
3434
struct hda_codec *codec = dev_get_drvdata(dev);
3535
snd_hda_update_power_acct(codec);
36-
return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
36+
return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
3737
}
3838

3939
static ssize_t power_off_acct_show(struct device *dev,
@@ -42,7 +42,7 @@ static ssize_t power_off_acct_show(struct device *dev,
4242
{
4343
struct hda_codec *codec = dev_get_drvdata(dev);
4444
snd_hda_update_power_acct(codec);
45-
return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
45+
return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_off_acct));
4646
}
4747

4848
static DEVICE_ATTR_RO(power_on_acct);
@@ -55,7 +55,7 @@ static ssize_t type##_show(struct device *dev, \
5555
char *buf) \
5656
{ \
5757
struct hda_codec *codec = dev_get_drvdata(dev); \
58-
return sprintf(buf, "0x%x\n", codec->field); \
58+
return sysfs_emit(buf, "0x%x\n", codec->field); \
5959
}
6060

6161
#define CODEC_INFO_STR_SHOW(type, field) \
@@ -64,8 +64,8 @@ static ssize_t type##_show(struct device *dev, \
6464
char *buf) \
6565
{ \
6666
struct hda_codec *codec = dev_get_drvdata(dev); \
67-
return sprintf(buf, "%s\n", \
68-
codec->field ? codec->field : ""); \
67+
return sysfs_emit(buf, "%s\n", \
68+
codec->field ? codec->field : ""); \
6969
}
7070

7171
CODEC_INFO_SHOW(vendor_id, core.vendor_id);
@@ -85,8 +85,8 @@ static ssize_t pin_configs_show(struct hda_codec *codec,
8585
int i, len = 0;
8686
mutex_lock(&codec->user_mutex);
8787
snd_array_for_each(list, i, pin) {
88-
len += sprintf(buf + len, "0x%02x 0x%08x\n",
89-
pin->nid, pin->cfg);
88+
len += sysfs_emit_at(buf, len, "0x%02x 0x%08x\n",
89+
pin->nid, pin->cfg);
9090
}
9191
mutex_unlock(&codec->user_mutex);
9292
return len;
@@ -222,9 +222,8 @@ static ssize_t init_verbs_show(struct device *dev,
222222
int i, len = 0;
223223
mutex_lock(&codec->user_mutex);
224224
snd_array_for_each(&codec->init_verbs, i, v) {
225-
len += scnprintf(buf + len, PAGE_SIZE - len,
226-
"0x%02x 0x%03x 0x%04x\n",
227-
v->nid, v->verb, v->param);
225+
len += sysfs_emit_at(buf, len, "0x%02x 0x%03x 0x%04x\n",
226+
v->nid, v->verb, v->param);
228227
}
229228
mutex_unlock(&codec->user_mutex);
230229
return len;
@@ -272,8 +271,8 @@ static ssize_t hints_show(struct device *dev,
272271
int i, len = 0;
273272
mutex_lock(&codec->user_mutex);
274273
snd_array_for_each(&codec->hints, i, hint) {
275-
len += scnprintf(buf + len, PAGE_SIZE - len,
276-
"%s = %s\n", hint->key, hint->val);
274+
len += sysfs_emit_at(buf, len, "%s = %s\n",
275+
hint->key, hint->val);
277276
}
278277
mutex_unlock(&codec->user_mutex);
279278
return len;

0 commit comments

Comments
 (0)