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

ALSA: rme96: Use snd_ctl_enum_info()

... and reduce the open codes. Also add missing const to text arrays.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

+21 -41
+21 -41
sound/pci/rme96.c
··· 1884 1884 static int 1885 1885 snd_rme96_info_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1886 1886 { 1887 - static char *_texts[5] = { "Optical", "Coaxial", "Internal", "XLR", "Analog" }; 1887 + static const char * const _texts[5] = { 1888 + "Optical", "Coaxial", "Internal", "XLR", "Analog" 1889 + }; 1888 1890 struct rme96 *rme96 = snd_kcontrol_chip(kcontrol); 1889 - char *texts[5] = { _texts[0], _texts[1], _texts[2], _texts[3], _texts[4] }; 1891 + const char *texts[5] = { 1892 + _texts[0], _texts[1], _texts[2], _texts[3], _texts[4] 1893 + }; 1894 + int num_items; 1890 1895 1891 - uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1892 - uinfo->count = 1; 1893 1896 switch (rme96->pci->device) { 1894 1897 case PCI_DEVICE_ID_RME_DIGI96: 1895 1898 case PCI_DEVICE_ID_RME_DIGI96_8: 1896 - uinfo->value.enumerated.items = 3; 1899 + num_items = 3; 1897 1900 break; 1898 1901 case PCI_DEVICE_ID_RME_DIGI96_8_PRO: 1899 - uinfo->value.enumerated.items = 4; 1902 + num_items = 4; 1900 1903 break; 1901 1904 case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST: 1902 1905 if (rme96->rev > 4) { 1903 1906 /* PST */ 1904 - uinfo->value.enumerated.items = 4; 1907 + num_items = 4; 1905 1908 texts[3] = _texts[4]; /* Analog instead of XLR */ 1906 1909 } else { 1907 1910 /* PAD */ 1908 - uinfo->value.enumerated.items = 5; 1911 + num_items = 5; 1909 1912 } 1910 1913 break; 1911 1914 default: 1912 1915 snd_BUG(); 1913 - break; 1916 + return -EINVAL; 1914 1917 } 1915 - if (uinfo->value.enumerated.item > uinfo->value.enumerated.items - 1) { 1916 - uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1917 - } 1918 - strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 1919 - return 0; 1918 + return snd_ctl_enum_info(uinfo, 1, num_items, texts); 1920 1919 } 1921 1920 static int 1922 1921 snd_rme96_get_inputtype_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) ··· 2001 2002 static int 2002 2003 snd_rme96_info_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2003 2004 { 2004 - static char *texts[3] = { "AutoSync", "Internal", "Word" }; 2005 + static const char * const texts[3] = { "AutoSync", "Internal", "Word" }; 2005 2006 2006 - uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2007 - uinfo->count = 1; 2008 - uinfo->value.enumerated.items = 3; 2009 - if (uinfo->value.enumerated.item > 2) { 2010 - uinfo->value.enumerated.item = 2; 2011 - } 2012 - strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2013 - return 0; 2007 + return snd_ctl_enum_info(uinfo, 1, 3, texts); 2014 2008 } 2015 2009 static int 2016 2010 snd_rme96_get_clockmode_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) ··· 2033 2041 static int 2034 2042 snd_rme96_info_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2035 2043 { 2036 - static char *texts[4] = { "0 dB", "-6 dB", "-12 dB", "-18 dB" }; 2044 + static const char * const texts[4] = { 2045 + "0 dB", "-6 dB", "-12 dB", "-18 dB" 2046 + }; 2037 2047 2038 - uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2039 - uinfo->count = 1; 2040 - uinfo->value.enumerated.items = 4; 2041 - if (uinfo->value.enumerated.item > 3) { 2042 - uinfo->value.enumerated.item = 3; 2043 - } 2044 - strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2045 - return 0; 2048 + return snd_ctl_enum_info(uinfo, 1, 4, texts); 2046 2049 } 2047 2050 static int 2048 2051 snd_rme96_get_attenuation_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) ··· 2068 2081 static int 2069 2082 snd_rme96_info_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2070 2083 { 2071 - static char *texts[4] = { "1+2", "3+4", "5+6", "7+8" }; 2084 + static const char * const texts[4] = { "1+2", "3+4", "5+6", "7+8" }; 2072 2085 2073 - uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2074 - uinfo->count = 1; 2075 - uinfo->value.enumerated.items = 4; 2076 - if (uinfo->value.enumerated.item > 3) { 2077 - uinfo->value.enumerated.item = 3; 2078 - } 2079 - strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2080 - return 0; 2086 + return snd_ctl_enum_info(uinfo, 1, 4, texts); 2081 2087 } 2082 2088 static int 2083 2089 snd_rme96_get_montracks_control(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)