Commit 17daae7a authored by Takashi Iwai's avatar Takashi Iwai
Browse files

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/20220801165639.26030-7-tiwai@suse.de


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 01043e3e
Loading
Loading
Loading
Loading
+21 −21
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@ static ssize_t type##_show(struct device *dev, \
			   char *buf)				\
			   char *buf)				\
{								\
{								\
	struct hdac_device *codec = dev_to_hdac_dev(dev);	\
	struct hdac_device *codec = dev_to_hdac_dev(dev);	\
	return sprintf(buf, "0x%x\n", codec->type);		\
	return sysfs_emit(buf, "0x%x\n", codec->type);		\
} \
} \
static DEVICE_ATTR_RO(type)
static DEVICE_ATTR_RO(type)


@@ -32,7 +32,7 @@ static ssize_t type##_show(struct device *dev, \
					char *buf)		\
					char *buf)		\
{								\
{								\
	struct hdac_device *codec = dev_to_hdac_dev(dev);	\
	struct hdac_device *codec = dev_to_hdac_dev(dev);	\
	return sprintf(buf, "%s\n",				\
	return sysfs_emit(buf, "%s\n",				\
			  codec->type ? codec->type : "");	\
			  codec->type ? codec->type : "");	\
} \
} \
static DEVICE_ATTR_RO(type)
static DEVICE_ATTR_RO(type)
@@ -161,7 +161,7 @@ static struct kobj_type widget_ktype = {
static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid,
static ssize_t caps_show(struct hdac_device *codec, hda_nid_t nid,
			struct widget_attribute *attr, char *buf)
			struct widget_attribute *attr, char *buf)
{
{
	return sprintf(buf, "0x%08x\n", get_wcaps(codec, nid));
	return sysfs_emit(buf, "0x%08x\n", get_wcaps(codec, nid));
}
}


static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid,
static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid,
@@ -169,7 +169,7 @@ static ssize_t pin_caps_show(struct hdac_device *codec, hda_nid_t nid,
{
{
	if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
	if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
		return 0;
		return 0;
	return sprintf(buf, "0x%08x\n",
	return sysfs_emit(buf, "0x%08x\n",
			  snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP));
			  snd_hdac_read_parm(codec, nid, AC_PAR_PIN_CAP));
}
}


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


static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid)
static bool has_pcm_cap(struct hdac_device *codec, hda_nid_t nid)
@@ -203,7 +203,7 @@ static ssize_t pcm_caps_show(struct hdac_device *codec, hda_nid_t nid,
{
{
	if (!has_pcm_cap(codec, nid))
	if (!has_pcm_cap(codec, nid))
		return 0;
		return 0;
	return sprintf(buf, "0x%08x\n",
	return sysfs_emit(buf, "0x%08x\n",
			  snd_hdac_read_parm(codec, nid, AC_PAR_PCM));
			  snd_hdac_read_parm(codec, nid, AC_PAR_PCM));
}
}


@@ -212,7 +212,7 @@ static ssize_t pcm_formats_show(struct hdac_device *codec, hda_nid_t nid,
{
{
	if (!has_pcm_cap(codec, nid))
	if (!has_pcm_cap(codec, nid))
		return 0;
		return 0;
	return sprintf(buf, "0x%08x\n",
	return sysfs_emit(buf, "0x%08x\n",
			  snd_hdac_read_parm(codec, nid, AC_PAR_STREAM));
			  snd_hdac_read_parm(codec, nid, AC_PAR_STREAM));
}
}


@@ -221,7 +221,7 @@ static ssize_t amp_in_caps_show(struct hdac_device *codec, hda_nid_t nid,
{
{
	if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
	if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
		return 0;
		return 0;
	return sprintf(buf, "0x%08x\n",
	return sysfs_emit(buf, "0x%08x\n",
			  snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP));
			  snd_hdac_read_parm(codec, nid, AC_PAR_AMP_IN_CAP));
}
}


@@ -230,7 +230,7 @@ static ssize_t amp_out_caps_show(struct hdac_device *codec, hda_nid_t nid,
{
{
	if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
	if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
		return 0;
		return 0;
	return sprintf(buf, "0x%08x\n",
	return sysfs_emit(buf, "0x%08x\n",
			  snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP));
			  snd_hdac_read_parm(codec, nid, AC_PAR_AMP_OUT_CAP));
}
}


@@ -239,14 +239,14 @@ static ssize_t power_caps_show(struct hdac_device *codec, hda_nid_t nid,
{
{
	if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER))
	if (nid != codec->afg && !(get_wcaps(codec, nid) & AC_WCAP_POWER))
		return 0;
		return 0;
	return sprintf(buf, "0x%08x\n",
	return sysfs_emit(buf, "0x%08x\n",
			  snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE));
			  snd_hdac_read_parm(codec, nid, AC_PAR_POWER_STATE));
}
}


static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid,
static ssize_t gpio_caps_show(struct hdac_device *codec, hda_nid_t nid,
			      struct widget_attribute *attr, char *buf)
			      struct widget_attribute *attr, char *buf)
{
{
	return sprintf(buf, "0x%08x\n",
	return sysfs_emit(buf, "0x%08x\n",
			  snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP));
			  snd_hdac_read_parm(codec, nid, AC_PAR_GPIO_CAP));
}
}


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


+11 −12
Original line number Original line Diff line number Diff line
@@ -33,7 +33,7 @@ static ssize_t power_on_acct_show(struct device *dev,
{
{
	struct hda_codec *codec = dev_get_drvdata(dev);
	struct hda_codec *codec = dev_get_drvdata(dev);
	snd_hda_update_power_acct(codec);
	snd_hda_update_power_acct(codec);
	return sprintf(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
	return sysfs_emit(buf, "%u\n", jiffies_to_msecs(codec->power_on_acct));
}
}


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


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


#define CODEC_INFO_STR_SHOW(type, field)			\
#define CODEC_INFO_STR_SHOW(type, field)			\
@@ -64,7 +64,7 @@ static ssize_t type##_show(struct device *dev, \
					char *buf)		\
					char *buf)		\
{								\
{								\
	struct hda_codec *codec = dev_get_drvdata(dev);		\
	struct hda_codec *codec = dev_get_drvdata(dev);		\
	return sprintf(buf, "%s\n",				\
	return sysfs_emit(buf, "%s\n",				\
			  codec->field ? codec->field : "");	\
			  codec->field ? codec->field : "");	\
}
}


@@ -85,7 +85,7 @@ static ssize_t pin_configs_show(struct hda_codec *codec,
	int i, len = 0;
	int i, len = 0;
	mutex_lock(&codec->user_mutex);
	mutex_lock(&codec->user_mutex);
	snd_array_for_each(list, i, pin) {
	snd_array_for_each(list, i, pin) {
		len += sprintf(buf + len, "0x%02x 0x%08x\n",
		len += sysfs_emit_at(buf, len, "0x%02x 0x%08x\n",
				     pin->nid, pin->cfg);
				     pin->nid, pin->cfg);
	}
	}
	mutex_unlock(&codec->user_mutex);
	mutex_unlock(&codec->user_mutex);
@@ -222,8 +222,7 @@ static ssize_t init_verbs_show(struct device *dev,
	int i, len = 0;
	int i, len = 0;
	mutex_lock(&codec->user_mutex);
	mutex_lock(&codec->user_mutex);
	snd_array_for_each(&codec->init_verbs, i, v) {
	snd_array_for_each(&codec->init_verbs, i, v) {
		len += scnprintf(buf + len, PAGE_SIZE - len,
		len += sysfs_emit_at(buf, len, "0x%02x 0x%03x 0x%04x\n",
				"0x%02x 0x%03x 0x%04x\n",
				     v->nid, v->verb, v->param);
				     v->nid, v->verb, v->param);
	}
	}
	mutex_unlock(&codec->user_mutex);
	mutex_unlock(&codec->user_mutex);
@@ -272,8 +271,8 @@ static ssize_t hints_show(struct device *dev,
	int i, len = 0;
	int i, len = 0;
	mutex_lock(&codec->user_mutex);
	mutex_lock(&codec->user_mutex);
	snd_array_for_each(&codec->hints, i, hint) {
	snd_array_for_each(&codec->hints, i, hint) {
		len += scnprintf(buf + len, PAGE_SIZE - len,
		len += sysfs_emit_at(buf, len, "%s = %s\n",
				"%s = %s\n", hint->key, hint->val);
				     hint->key, hint->val);
	}
	}
	mutex_unlock(&codec->user_mutex);
	mutex_unlock(&codec->user_mutex);
	return len;
	return len;