[alsa-devel] [PATCH 0/5] ALSA: Fix uapi headers
Hi,
here is a series of fixes for include/uapi/sound/*.h files and the relevant code changes, so that they can be used for building alsa-tools programs again.
The corresponding alsa-lib update will be followed.
Takashi
===
Takashi Iwai (5): ALSA: emu10k1: Make uapi/emu10k1.h compilable again ALSA: hdsp: Make uapi/hdsp.h compilable again ALSA: hdspm: Drop linux/types.h inclusion in uapi header ALSA: uapi: Fix typos and header inclusion in asound.h ALSA: uapi: Drop asound.h inclusion from asoc.h
include/uapi/sound/asoc.h | 1 - include/uapi/sound/asound.h | 6 +++--- include/uapi/sound/emu10k1.h | 38 ++++++++++++++++++++++++++------------ include/uapi/sound/hdsp.h | 4 +--- include/uapi/sound/hdspm.h | 2 -- sound/pci/emu10k1/emufx.c | 26 ++++++++++++++------------ sound/pci/rme9652/hdsp.c | 2 +- 7 files changed, 45 insertions(+), 34 deletions(-)
Recently we updated the content in alsa-lib uapi header files by just copying from the latest Linus kernel uapi/*.h, and noticed that it broke the build of some alsa-tools programs. The reason is that we used to have a modified version in the past, so that the program can be built without referring to the unexported stuff like snd_ctl_elem_id or __user prefix.
This patch attempts to restore that, i.e. dropping the stuff that can't be referred in the user-space. For adapting the changes in uapi/emu10k1.h, the emu10k1 driver code is also slightly modified. Most of changes are pointer cast.
Signed-off-by: Takashi Iwai tiwai@suse.de --- include/uapi/sound/emu10k1.h | 38 ++++++++++++++++++++++++++------------ sound/pci/emu10k1/emufx.c | 26 ++++++++++++++------------ 2 files changed, 40 insertions(+), 24 deletions(-)
diff --git a/include/uapi/sound/emu10k1.h b/include/uapi/sound/emu10k1.h index 042c5a6f16ee..c1150e4d0231 100644 --- a/include/uapi/sound/emu10k1.h +++ b/include/uapi/sound/emu10k1.h @@ -23,9 +23,6 @@ #ifndef _UAPI__SOUND_EMU10K1_H #define _UAPI__SOUND_EMU10K1_H
-#include <linux/types.h> -#include <sound/asound.h> - /* * ---- FX8010 ---- */ @@ -282,8 +279,22 @@ struct snd_emu10k1_fx8010_info { #define EMU10K1_GPR_TRANSLATION_TREBLE 3 #define EMU10K1_GPR_TRANSLATION_ONOFF 4
+enum emu10k1_ctl_elem_iface { + EMU10K1_CTL_ELEM_IFACE_MIXER = 2, /* virtual mixer device */ + EMU10K1_CTL_ELEM_IFACE_PCM = 3, /* PCM device */ +}; + +struct emu10k1_ctl_elem_id { + unsigned int pad; /* don't use */ + int iface; /* interface identifier */ + unsigned int device; /* device/client number */ + unsigned int subdevice; /* subdevice (substream) number */ + unsigned char name[44]; /* ASCII name of item */ + unsigned int index; /* index of item */ +}; + struct snd_emu10k1_fx8010_control_gpr { - struct snd_ctl_elem_id id; /* full control ID definition */ + struct emu10k1_ctl_elem_id id; /* full control ID definition */ unsigned int vcount; /* visible count */ unsigned int count; /* count of GPR (1..16) */ unsigned short gpr[32]; /* GPR number(s) */ @@ -296,7 +307,7 @@ struct snd_emu10k1_fx8010_control_gpr {
/* old ABI without TLV support */ struct snd_emu10k1_fx8010_control_old_gpr { - struct snd_ctl_elem_id id; + struct emu10k1_ctl_elem_id id; unsigned int vcount; unsigned int count; unsigned short gpr[32]; @@ -310,24 +321,24 @@ struct snd_emu10k1_fx8010_code { char name[128];
__EMU10K1_DECLARE_BITMAP(gpr_valid, 0x200); /* bitmask of valid initializers */ - __u32 __user *gpr_map; /* initializers */ + __u32 *gpr_map; /* initializers */
unsigned int gpr_add_control_count; /* count of GPR controls to add/replace */ - struct snd_emu10k1_fx8010_control_gpr __user *gpr_add_controls; /* GPR controls to add/replace */ + struct snd_emu10k1_fx8010_control_gpr *gpr_add_controls; /* GPR controls to add/replace */
unsigned int gpr_del_control_count; /* count of GPR controls to remove */ - struct snd_ctl_elem_id __user *gpr_del_controls; /* IDs of GPR controls to remove */ + struct emu10k1_ctl_elem_id *gpr_del_controls; /* IDs of GPR controls to remove */
unsigned int gpr_list_control_count; /* count of GPR controls to list */ unsigned int gpr_list_control_total; /* total count of GPR controls */ - struct snd_emu10k1_fx8010_control_gpr __user *gpr_list_controls; /* listed GPR controls */ + struct snd_emu10k1_fx8010_control_gpr *gpr_list_controls; /* listed GPR controls */
__EMU10K1_DECLARE_BITMAP(tram_valid, 0x100); /* bitmask of valid initializers */ - __u32 __user *tram_data_map; /* data initializers */ - __u32 __user *tram_addr_map; /* map initializers */ + __u32 *tram_data_map; /* data initializers */ + __u32 *tram_addr_map; /* map initializers */
__EMU10K1_DECLARE_BITMAP(code_valid, 1024); /* bitmask of valid instructions */ - __u32 __user *code; /* one instruction - 64 bits */ + __u32 *code; /* one instruction - 64 bits */ };
struct snd_emu10k1_fx8010_tram { @@ -371,11 +382,14 @@ struct snd_emu10k1_fx8010_pcm_rec { #define SNDRV_EMU10K1_IOCTL_SINGLE_STEP _IOW ('H', 0x83, int) #define SNDRV_EMU10K1_IOCTL_DBG_READ _IOR ('H', 0x84, int)
+#ifndef __KERNEL__ /* typedefs for compatibility to user-space */ typedef struct snd_emu10k1_fx8010_info emu10k1_fx8010_info_t; typedef struct snd_emu10k1_fx8010_control_gpr emu10k1_fx8010_control_gpr_t; typedef struct snd_emu10k1_fx8010_code emu10k1_fx8010_code_t; typedef struct snd_emu10k1_fx8010_tram emu10k1_fx8010_tram_t; typedef struct snd_emu10k1_fx8010_pcm_rec emu10k1_fx8010_pcm_t; +typedef struct emu10k1_ctl_elem_id emu10k1_ctl_elem_id_t; +#endif
#endif /* _UAPI__SOUND_EMU10K1_H */ diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c index a31adecfe608..e0e076a9c321 100644 --- a/sound/pci/emu10k1/emufx.c +++ b/sound/pci/emu10k1/emufx.c @@ -628,7 +628,7 @@ static int snd_emu10k1_code_peek(struct snd_emu10k1 *emu, }
static struct snd_emu10k1_fx8010_ctl * -snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, struct snd_ctl_elem_id *id) +snd_emu10k1_look_for_ctl(struct snd_emu10k1 *emu, struct emu10k1_ctl_elem_id *id) { struct snd_emu10k1_fx8010_ctl *ctl; struct snd_kcontrol *kcontrol; @@ -714,15 +714,15 @@ static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu, bool in_kernel) { unsigned int i; - struct snd_ctl_elem_id __user *_id; - struct snd_ctl_elem_id id; + struct emu10k1_ctl_elem_id __user *_id; + struct emu10k1_ctl_elem_id id; struct snd_emu10k1_fx8010_control_gpr *gctl; int err; - for (i = 0, _id = icode->gpr_del_controls; - i < icode->gpr_del_control_count; i++, _id++) { + _id = (__force struct emu10k1_ctl_elem_id __user *)icode->gpr_del_controls; + for (i = 0; i < icode->gpr_del_control_count; i++, _id++) { if (in_kernel) - id = *(__force struct snd_ctl_elem_id *)_id; + id = *(__force struct emu10k1_ctl_elem_id *)_id; else if (copy_from_user(&id, _id, sizeof(id))) return -EFAULT; if (snd_emu10k1_look_for_ctl(emu, &id) == NULL) @@ -741,7 +741,8 @@ static int snd_emu10k1_verify_controls(struct snd_emu10k1 *emu, if (snd_emu10k1_look_for_ctl(emu, &gctl->id)) continue; down_read(&emu->card->controls_rwsem); - if (snd_ctl_find_id(emu->card, &gctl->id) != NULL) { + if (snd_ctl_find_id(emu->card, + (struct snd_ctl_elem_id *)&gctl->id)) { up_read(&emu->card->controls_rwsem); err = -EEXIST; goto __error; @@ -876,15 +877,16 @@ static int snd_emu10k1_del_controls(struct snd_emu10k1 *emu, bool in_kernel) { unsigned int i; - struct snd_ctl_elem_id id; - struct snd_ctl_elem_id __user *_id; + struct emu10k1_ctl_elem_id id; + struct emu10k1_ctl_elem_id __user *_id; struct snd_emu10k1_fx8010_ctl *ctl; struct snd_card *card = emu->card; - for (i = 0, _id = icode->gpr_del_controls; - i < icode->gpr_del_control_count; i++, _id++) { + _id = (__force struct emu10k1_ctl_elem_id __user *)icode->gpr_del_controls; + + for (i = 0; i < icode->gpr_del_control_count; i++, _id++) { if (in_kernel) - id = *(__force struct snd_ctl_elem_id *)_id; + id = *(__force struct emu10k1_ctl_elem_id *)_id; else if (copy_from_user(&id, _id, sizeof(id))) return -EFAULT; down_write(&card->controls_rwsem);
Recently alsa-lib updated its content of sound/hdsp.h just by copying the latest Linus kernel uapi/*.h, and this broke the build of alsa-tools programs. We used to modify the headers so that they can be built without asoundlib.h and linux kernel headers, and the verbatim copy doesn't work as is.
This patch removes again the linux/types.h inclusion and drop __user prefix that broke the build and adjusts the corresponding code.
Signed-off-by: Takashi Iwai tiwai@suse.de --- include/uapi/sound/hdsp.h | 4 +--- sound/pci/rme9652/hdsp.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/include/uapi/sound/hdsp.h b/include/uapi/sound/hdsp.h index 5dc0c3db0a4c..88c92a3fb477 100644 --- a/include/uapi/sound/hdsp.h +++ b/include/uapi/sound/hdsp.h @@ -20,8 +20,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <linux/types.h> - #define HDSP_MATRIX_MIXER_SIZE 2048
enum HDSP_IO_Type { @@ -74,7 +72,7 @@ struct hdsp_config_info { #define SNDRV_HDSP_IOCTL_GET_CONFIG_INFO _IOR('H', 0x41, struct hdsp_config_info)
struct hdsp_firmware { - void __user *firmware_data; /* 24413 x 4 bytes */ + void *firmware_data; /* 24413 x 4 bytes */ };
#define SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE _IOW('H', 0x42, struct hdsp_firmware) diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index 87e60dd13066..b4c42c4fa201 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -4817,7 +4817,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne "initializing firmware upload\n"); firmware = (struct hdsp_firmware __user *)argp;
- if (get_user(firmware_data, &firmware->firmware_data)) + if (get_user(firmware_data, (__force void __user **)&firmware->firmware_data)) return -EFAULT;
if (hdsp_check_for_iobox (hdsp))
The hdspm.h uapi header has been used also from non-Linux or platforms that don't have linux/*.h. It was OK in the past because alsa-lib contained the modified version of this header file, but now it tries to the verbatim copy, so it broke the build. This fixes it again.
Signed-off-by: Takashi Iwai tiwai@suse.de --- include/uapi/sound/hdspm.h | 2 -- 1 file changed, 2 deletions(-)
diff --git a/include/uapi/sound/hdspm.h b/include/uapi/sound/hdspm.h index a38f3f79beb7..2d91f90eb5e1 100644 --- a/include/uapi/sound/hdspm.h +++ b/include/uapi/sound/hdspm.h @@ -21,8 +21,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <linux/types.h> - /* Maximum channels is 64 even on 56Mode you have 64playbacks to matrix */ #define HDSPM_MAX_CHANNELS 64
The recent changes in uapi/asoundlib.h caused some build errors in alsa-lib side because of a typo and the new included files. Basically asound.h is supposed to be usable also on non-Linux systems, so we've tried to avoid the Linux-specific include files.
This patch is an attempt to recover from those changes.
Fixes: 3ddee7f88aaf ("ALSA: Avoid using timespec for struct snd_pcm_status") Fixes: 80fe7430c708 ("ALSA: add new 32-bit layout for snd_pcm_mmap_status/control") Signed-off-by: Takashi Iwai tiwai@suse.de --- include/uapi/sound/asound.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h index e6a958b8aff1..e7943302359e 100644 --- a/include/uapi/sound/asound.h +++ b/include/uapi/sound/asound.h @@ -26,7 +26,9 @@
#if defined(__KERNEL__) || defined(__linux__) #include <linux/types.h> +#include <asm/byteorder.h> #else +#include <endian.h> #include <sys/ioctl.h> #endif
@@ -35,8 +37,6 @@ #include <time.h> #endif
-#include <asm/byteorder.h> - /* * protocol version */ @@ -471,7 +471,7 @@ enum {
#ifndef __KERNEL__ /* explicit padding avoids incompatibility between i386 and x86-64 */ -typedef struct { unsigned char pad[sizeof(time_t) - sizeof(int)] __time_pad; +typedef struct { unsigned char pad[sizeof(time_t) - sizeof(int)]; } __time_pad;
struct snd_pcm_status { snd_pcm_state_t state; /* stream state */
The asound.h isn't always available while asoc.h itself is distributed in alsa-lib package. So we need to avoid the unnecessary inclusion of asound.h from there.
Signed-off-by: Takashi Iwai tiwai@suse.de --- include/uapi/sound/asoc.h | 1 - 1 file changed, 1 deletion(-)
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index a74ca232f1fc..6048553c119d 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -17,7 +17,6 @@ #define __LINUX_UAPI_SND_ASOC_H
#include <linux/types.h> -#include <sound/asound.h>
/* * Maximum number of channels topology kcontrol can represent.
Hi,
On Fri, Dec 20, 2019 at 04:34:15PM +0100, Takashi Iwai wrote:
The asound.h isn't always available while asoc.h itself is distributed in alsa-lib package. So we need to avoid the unnecessary inclusion of asound.h from there.
Signed-off-by: Takashi Iwai tiwai@suse.de
include/uapi/sound/asoc.h | 1 - 1 file changed, 1 deletion(-)
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index a74ca232f1fc..6048553c119d 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -17,7 +17,6 @@ #define __LINUX_UAPI_SND_ASOC_H
#include <linux/types.h> -#include <sound/asound.h>
/*
- Maximum number of channels topology kcontrol can represent.
This has reached v5.6 and caused the following regression:
sound/asoc.h:214:14: error: 'SNDRV_CTL_ELEM_ID_NAME_MAXLEN' undeclared here (not in a function) 214 | char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
Please revert or fix in some way to make the uapi header compileable again.
Thanks,
On Mon, 30 Mar 2020 18:53:11 +0200, Dmitry V. Levin wrote:
Hi,
On Fri, Dec 20, 2019 at 04:34:15PM +0100, Takashi Iwai wrote:
The asound.h isn't always available while asoc.h itself is distributed in alsa-lib package. So we need to avoid the unnecessary inclusion of asound.h from there.
Signed-off-by: Takashi Iwai tiwai@suse.de
include/uapi/sound/asoc.h | 1 - 1 file changed, 1 deletion(-)
diff --git a/include/uapi/sound/asoc.h b/include/uapi/sound/asoc.h index a74ca232f1fc..6048553c119d 100644 --- a/include/uapi/sound/asoc.h +++ b/include/uapi/sound/asoc.h @@ -17,7 +17,6 @@ #define __LINUX_UAPI_SND_ASOC_H
#include <linux/types.h> -#include <sound/asound.h>
/*
- Maximum number of channels topology kcontrol can represent.
This has reached v5.6 and caused the following regression:
sound/asoc.h:214:14: error: 'SNDRV_CTL_ELEM_ID_NAME_MAXLEN' undeclared here (not in a function) 214 | char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
What program caused it? The change was done because it broke (already years log) the old alsa-lib code. So reverting it will break it again.
OTOH, alsa-lib breakage could be worked around inside alsa-lib, so likely I'm going to revert it. But I'd like to know exact cases.
thanks,
Takashi
Please revert or fix in some way to make the uapi header compileable again.
Thanks,
-- ldv
participants (2)
-
Dmitry V. Levin
-
Takashi Iwai