On Wed, 15 Feb 2017 18:32:07 +0100, Detlef Urban wrote:
It seems that my approach to add names to snd_ctl_elem_info enumeration is wrong (see bleow). I couldn't find documentation or any example to lean on. Any hints ?
-------- Weitergeleitete Nachricht -------- Betreff: Re: [alsa-devel] [PATCH v6 1/1] ALSA: Tascam US-16x08 DSP mixer quirk Datum: Wed, 15 Feb 2017 23:46:04 +0800 Von: kbuild test robot lkp@intel.com An: OnkelDead onkel@paraair.de Kopie (CC): OnkelDead onkel@paraair.de, alsa-devel@alsa-project.org, kbuild-all@01.org, tiwai@suse.com
Hi OnkelDead,
[auto build test WARNING on sound/for-next] [also build test WARNING on v4.10-rc8 next-20170215] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/OnkelDead/ALSA-Tascam-US-16x08-DSP-... base: https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next config: blackfin-allmodconfig (attached as .config) compiler: bfin-uclinux-gcc (GCC) 6.2.0 reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/ma... -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=blackfin
All warnings (new ones prefixed by >>):
sound/usb/mixer_us16x08.c: In function 'snd_us16x08_route_info':
sound/usb/mixer_us16x08.c:201:38: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
uinfo->value.enumerated.names_ptr = (__u64) route_names; ^
vim +201 sound/usb/mixer_us16x08.c
185 } 186 187 return err; 188 } 189 190 static int snd_us16x08_route_info(struct snd_kcontrol *kcontrol, 191 struct snd_ctl_elem_info *uinfo) 192 { 193 int i; 194 195 uinfo->count = 1; 196 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 197 uinfo->value.integer.max = SND_US16X08_KCMAX(kcontrol); 198 uinfo->value.integer.min = SND_US16X08_KCMIN(kcontrol); 199 uinfo->value.integer.step = SND_US16X08_KCSTEP(kcontrol); 200 uinfo->value.enumerated.items = 10;
201 uinfo->value.enumerated.names_ptr = (__u64) route_names;
202 uinfo->value.enumerated.names_length = 0; 203 for (i = 0; i < 10; i++) 204 uinfo->value.enumerated.names_length += 205 strlen(route_names[i]) + 1; 206 return 0; 207 }
The code does wrong in multiple ways.
First off, if you use ENUMERATED type, you can't set uinfo->value.integer.*, but you can set only uinfo->value.enumerated.*. It's a union, so you know why.
Second, value.enumerated.names_ptr and value.enumerated.names_length are not used for the normal kctls, it's only for special kctls. Leave them.
Third, the concept of enum kctl info callback is to return only three things: count, value.enumerated.items, and value.enumerated.name. The first one is the size of the array, the second is the size of the enum list, and the third one is the enum string corresponding to the value.enumearted.item given by the caller.
And, the solution is, like Clemens already mentioned, to use snd_ctl_enum_info() helper function:
static int snd_us16x08_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { return snd_ctl_enum_info(uinfo, 1, 10, route_names); }
Takashi