ALSA: hda: Add hda_append_suffix() local helper
PATCH 1/1 ALSA: hda: Add hda_append_suffix() local helper
As strlcat() shall be deprecated in future, provide an alternative just for a simple purpose -- append a suffix string to the given string buffer -- and use it at appropriate places. The code isn't really efficient, but we don't ask for speed here, so let it be.
--- sound/hda/codecs/generic.c | 4 ++-- sound/hda/common/hda_local.h | 7 +++++++ sound/hda/common/jack.c | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-)
sound/hda/codecs/generic.c +2 -2
@@ -2701,7 +2701,7 @@ static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin,struct hda_gen_spec *spec = codec->spec;snd_hda_get_pin_label (codec, pin, &spec->autocfg, name, name_len); -strlcat (name," Jack Mode" , name_len); +hda_append_suffix (name," Jack Mode" , name_len); }static int get_out_jack_num_items (struct hda_codec *codec,hda_nid_t pin)
@@ -5678,7 +5678,7 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,break ; } } -strlcat (str, sfx, len); +hda_append_suffix (str, sfx, len); }/* copy PCM stream info from @default_str, and override non-NULL entries
sound/hda/common/hda_local.h +7 -0
@@ -723,4 +723,11 @@ void snd_hda_codec_display_power(struct hda_codec *codec, bool enable); #define codec_dbg(codec, fmt, args...) \ dev_dbg(hda_codec_dev(codec), fmt, ##args) +/* append a suffix string safely; equivalent with strlcat() */ +static inline void hda_append_suffix (char *str,const char *suffix,size_t size) +{ +size_t len =strnlen (str, size); +strscpy (str + len, suffix, size - len); +} +#endif /* __SOUND_HDA_LOCAL_H */
sound/hda/common/jack.c +1 -1
@@ -615,7 +615,7 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,snd_hda_get_pin_label (codec, nid, cfg, name,sizeof (name));if (phantom_jack)/* Example final name: "Internal Mic Phantom Jack" */ -strncat (name," Phantom" ,sizeof (name) -strlen (name) -1 ); +hda_append_suffix (name," Phantom" ,sizeof (name)); err =snd_hda_jack_add_kctl (codec, nid, name, phantom_jack,0 ,NULL );if (err <0 )return err;
Signature · 1 line
2.55.0
Quoted 4 lines · Takashi Iwai
As
strlcat()shall be deprecated in future, provide an alternative just for a simple purpose -- append a suffix string to the given string buffer -- and use it at appropriate places. The code isn't really efficient, but we don't ask for speed here, so let it be.
The patch was tested as follows:
- Applied on today's for-next (f817bac425c5) on top of the two jack name cleanup patches. W=1 build of sound/hda/, no new warnings.
- A userspace harness compared hda_append_suffix() against both the kernel strlcat() and the strncat() form in jack.c, exhaustively over buffer sizes, fill levels and suffix lengths, comparing every byte of the buffer. All cases were byte identical, including truncation.
- A QEMU boot with intel-hda and hda-duplex, comparing the PCM stream names, the codec proc dump and the full control element list between base and patched kernels. The captures were byte identical.
Ian
Quoted 22 lines · Ian Bridges
Quoted 4 lines · Takashi Iwai
As
strlcat()shall be deprecated in future, provide an alternative just for a simple purpose -- append a suffix string to the given string buffer -- and use it at appropriate places. The code isn't really efficient, but we don't ask for speed here, so let it be.The patch was tested as follows:
- Applied on today's for-next (f817bac425c5) on top of the two jack name cleanup patches. W=1 build ofsound/hda/, no new warnings.- A userspace harness compared
hda_append_suffix()against both the kernelstrlcat()and thestrncat()form injack.c, exhaustively over buffer sizes, fill levels and suffix lengths, comparing every byte of the buffer. All cases were byte identical, including truncation.- A QEMU boot with intel-hda and hda-duplex, comparing the PCM stream names, the codec proc dump and the full control element list between base and patched kernels. The captures were byte identical.
Quoted 4 lines
Ian
Reviewed-by Ian Bridges <[email protected]>Tested-by Ian Bridges <[email protected]>
Thanks for checking. Applied now to for-next branch.
Takashi