linux_dsm_epyc7002/sound/usb/usx2y/usbusx2y.h
Gustavo A. R. Silva 9ad06ebb9a ALSA: Replace zero-length array with flexible-array
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

sizeof(flexible-array-member) triggers a warning because flexible array
members have incomplete type[1]. There are some instances of code in
which the sizeof operator is being incorrectly/erroneously applied to
zero-length arrays and the result is zero. Such instances may be hiding
some bugs. So, this work (flexible-array member conversions) will also
help to get completely rid of those sorts of issues.

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 7649773293 ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20200507192223.GA16335@embeddedor
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-05-07 22:30:36 +02:00

90 lines
2.1 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef USBUSX2Y_H
#define USBUSX2Y_H
#include "../usbaudio.h"
#include "../midi.h"
#include "usbus428ctldefs.h"
#define NRURBS 2
#define URBS_AsyncSeq 10
#define URB_DataLen_AsyncSeq 32
struct snd_usX2Y_AsyncSeq {
struct urb *urb[URBS_AsyncSeq];
char *buffer;
};
struct snd_usX2Y_urbSeq {
int submitted;
int len;
struct urb *urb[];
};
#include "usx2yhwdeppcm.h"
struct usX2Ydev {
struct usb_device *dev;
int card_index;
int stride;
struct urb *In04urb;
void *In04Buf;
char In04Last[24];
unsigned In04IntCalls;
struct snd_usX2Y_urbSeq *US04;
wait_queue_head_t In04WaitQueue;
struct snd_usX2Y_AsyncSeq AS04;
unsigned int rate,
format;
int chip_status;
struct mutex pcm_mutex;
struct us428ctls_sharedmem *us428ctls_sharedmem;
int wait_iso_frame;
wait_queue_head_t us428ctls_wait_queue_head;
struct snd_usX2Y_hwdep_pcm_shm *hwdep_pcm_shm;
struct snd_usX2Y_substream *subs[4];
struct snd_usX2Y_substream * volatile prepare_subs;
wait_queue_head_t prepare_wait_queue;
struct list_head midi_list;
struct list_head pcm_list;
int pcm_devs;
};
struct snd_usX2Y_substream {
struct usX2Ydev *usX2Y;
struct snd_pcm_substream *pcm_substream;
int endpoint;
unsigned int maxpacksize; /* max packet size in bytes */
atomic_t state;
#define state_STOPPED 0
#define state_STARTING1 1
#define state_STARTING2 2
#define state_STARTING3 3
#define state_PREPARED 4
#define state_PRERUNNING 6
#define state_RUNNING 8
int hwptr; /* free frame position in the buffer (only for playback) */
int hwptr_done; /* processed frame position in the buffer */
int transfer_done; /* processed frames since last period update */
struct urb *urb[NRURBS]; /* data urb table */
struct urb *completed_urb;
char *tmpbuf; /* temporary buffer for playback */
};
#define usX2Y(c) ((struct usX2Ydev *)(c)->private_data)
int usX2Y_audio_create(struct snd_card *card);
int usX2Y_AsyncSeq04_init(struct usX2Ydev *usX2Y);
int usX2Y_In04_init(struct usX2Ydev *usX2Y);
#define NAME_ALLCAPS "US-X2Y"
#endif