Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: hda: Use safer strscpy() instead of strcpy()

Use a safer function strscpy() instead of strcpy() for copying to
arrays.

Only idiomatic code replacement, and no functional changes.

Link: https://patch.msgid.link/20250711083051.18759-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+16 -16
+9 -9
sound/hda/codecs/ca0132.c
··· 5796 5796 if (uinfo->value.enumerated.item >= MIC_BOOST_NUM_OF_STEPS) 5797 5797 uinfo->value.enumerated.item = MIC_BOOST_NUM_OF_STEPS - 1; 5798 5798 sprintf(namestr, "%d %s", (uinfo->value.enumerated.item * 10), sfx); 5799 - strcpy(uinfo->value.enumerated.name, namestr); 5799 + strscpy(uinfo->value.enumerated.name, namestr); 5800 5800 return 0; 5801 5801 } 5802 5802 ··· 5850 5850 sprintf(namestr, "%s %s", 5851 5851 ae5_headphone_gain_presets[uinfo->value.enumerated.item].name, 5852 5852 sfx); 5853 - strcpy(uinfo->value.enumerated.name, namestr); 5853 + strscpy(uinfo->value.enumerated.name, namestr); 5854 5854 return 0; 5855 5855 } 5856 5856 ··· 5903 5903 uinfo->value.enumerated.item = AE5_SOUND_FILTER_MAX - 1; 5904 5904 sprintf(namestr, "%s", 5905 5905 ae5_filter_presets[uinfo->value.enumerated.item].name); 5906 - strcpy(uinfo->value.enumerated.name, namestr); 5906 + strscpy(uinfo->value.enumerated.name, namestr); 5907 5907 return 0; 5908 5908 } 5909 5909 ··· 5952 5952 uinfo->value.enumerated.items = IN_SRC_NUM_OF_INPUTS; 5953 5953 if (uinfo->value.enumerated.item >= IN_SRC_NUM_OF_INPUTS) 5954 5954 uinfo->value.enumerated.item = IN_SRC_NUM_OF_INPUTS - 1; 5955 - strcpy(uinfo->value.enumerated.name, 5955 + strscpy(uinfo->value.enumerated.name, 5956 5956 in_src_str[uinfo->value.enumerated.item]); 5957 5957 return 0; 5958 5958 } ··· 6004 6004 uinfo->value.enumerated.items = NUM_OF_OUTPUTS; 6005 6005 if (uinfo->value.enumerated.item >= NUM_OF_OUTPUTS) 6006 6006 uinfo->value.enumerated.item = NUM_OF_OUTPUTS - 1; 6007 - strcpy(uinfo->value.enumerated.name, 6007 + strscpy(uinfo->value.enumerated.name, 6008 6008 out_type_str[uinfo->value.enumerated.item]); 6009 6009 return 0; 6010 6010 } ··· 6055 6055 uinfo->value.enumerated.items = items; 6056 6056 if (uinfo->value.enumerated.item >= items) 6057 6057 uinfo->value.enumerated.item = items - 1; 6058 - strcpy(uinfo->value.enumerated.name, 6058 + strscpy(uinfo->value.enumerated.name, 6059 6059 speaker_channel_cfgs[uinfo->value.enumerated.item].name); 6060 6060 return 0; 6061 6061 } ··· 6108 6108 uinfo->value.enumerated.items = NUM_OF_SVM_SETTINGS; 6109 6109 if (uinfo->value.enumerated.item >= NUM_OF_SVM_SETTINGS) 6110 6110 uinfo->value.enumerated.item = NUM_OF_SVM_SETTINGS - 1; 6111 - strcpy(uinfo->value.enumerated.name, 6111 + strscpy(uinfo->value.enumerated.name, 6112 6112 out_svm_set_enum_str[uinfo->value.enumerated.item]); 6113 6113 return 0; 6114 6114 } ··· 6172 6172 uinfo->value.enumerated.items = items; 6173 6173 if (uinfo->value.enumerated.item >= items) 6174 6174 uinfo->value.enumerated.item = items - 1; 6175 - strcpy(uinfo->value.enumerated.name, 6175 + strscpy(uinfo->value.enumerated.name, 6176 6176 ca0132_alt_eq_presets[uinfo->value.enumerated.item].name); 6177 6177 return 0; 6178 6178 } ··· 6229 6229 uinfo->value.enumerated.items = items; 6230 6230 if (uinfo->value.enumerated.item >= items) 6231 6231 uinfo->value.enumerated.item = items - 1; 6232 - strcpy(uinfo->value.enumerated.name, 6232 + strscpy(uinfo->value.enumerated.name, 6233 6233 ca0132_voicefx_presets[uinfo->value.enumerated.item].name); 6234 6234 return 0; 6235 6235 }
+2 -2
sound/hda/codecs/generic.c
··· 2828 2828 snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps), 2829 2829 vref_texts); 2830 2830 /* set the right text */ 2831 - strcpy(uinfo->value.enumerated.name, 2831 + strscpy(uinfo->value.enumerated.name, 2832 2832 vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]); 2833 2833 return 0; 2834 2834 } ··· 2941 2941 text = "Mic In"; 2942 2942 } 2943 2943 2944 - strcpy(uinfo->value.enumerated.name, text); 2944 + strscpy(uinfo->value.enumerated.name, text); 2945 2945 return 0; 2946 2946 } 2947 2947
+2 -2
sound/hda/codecs/realtek/realtek.c
··· 1130 1130 switch (action) { 1131 1131 case HDA_FIXUP_ACT_PRE_PROBE: 1132 1132 /* override card longname to provide a unique UCM profile */ 1133 - strcpy(codec->card->longname, "HDAudio-Gigabyte-ALC1220DualCodecs"); 1133 + strscpy(codec->card->longname, "HDAudio-Gigabyte-ALC1220DualCodecs"); 1134 1134 break; 1135 1135 case HDA_FIXUP_ACT_BUILD: 1136 1136 /* rename Capture controls depending on the codec */ ··· 1155 1155 switch (action) { 1156 1156 case HDA_FIXUP_ACT_PRE_PROBE: 1157 1157 /* override card longname to provide a unique UCM profile */ 1158 - strcpy(codec->card->longname, "HDAudio-Lenovo-DualCodecs"); 1158 + strscpy(codec->card->longname, "HDAudio-Lenovo-DualCodecs"); 1159 1159 break; 1160 1160 case HDA_FIXUP_ACT_BUILD: 1161 1161 /* rename Capture controls depending on the codec */
+2 -2
sound/hda/common/codec.c
··· 1638 1638 id.index = idx; 1639 1639 if (snd_BUG_ON(strlen(name) >= sizeof(id.name))) 1640 1640 return NULL; 1641 - strcpy(id.name, name); 1641 + strscpy(id.name, name); 1642 1642 return snd_ctl_find_id(codec->card, &id); 1643 1643 } 1644 1644 ··· 3508 3508 index = uinfo->value.enumerated.item; 3509 3509 if (index >= imux->num_items) 3510 3510 index = imux->num_items - 1; 3511 - strcpy(uinfo->value.enumerated.name, imux->items[index].label); 3511 + strscpy(uinfo->value.enumerated.name, imux->items[index].label); 3512 3512 return 0; 3513 3513 } 3514 3514 EXPORT_SYMBOL_GPL(snd_hda_input_mux_info);
+1 -1
sound/hda/controllers/intel.c
··· 2024 2024 if (azx_acquire_irq(chip, 0) < 0) 2025 2025 return -EBUSY; 2026 2026 2027 - strcpy(card->driver, "HDA-Intel"); 2027 + strscpy(card->driver, "HDA-Intel"); 2028 2028 strscpy(card->shortname, driver_short_names[chip->driver_type], 2029 2029 sizeof(card->shortname)); 2030 2030 snprintf(card->longname, sizeof(card->longname),