Skip to content

Commit

Permalink
ALSA: line6: Use container_of()
Browse files Browse the repository at this point in the history
... instead of unconditional cast.

Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed May 28, 2019
1 parent be8fd48 commit f23a09e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
12 changes: 7 additions & 5 deletions sound/usb/line6/pod.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct usb_line6_pod {
int device_id;
};

#define line6_to_pod(x) container_of(x, struct usb_line6_pod, line6)

#define POD_SYSEX_CODE 3

/* *INDENT-OFF* */
Expand Down Expand Up @@ -177,7 +179,7 @@ static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
*/
static void line6_pod_process_message(struct usb_line6 *line6)
{
struct usb_line6_pod *pod = (struct usb_line6_pod *) line6;
struct usb_line6_pod *pod = line6_to_pod(line6);
const unsigned char *buf = pod->line6.buffer_message;

if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) {
Expand Down Expand Up @@ -274,7 +276,7 @@ static ssize_t device_id_show(struct device *dev,

static void pod_startup(struct usb_line6 *line6)
{
struct usb_line6_pod *pod = (struct usb_line6_pod *) line6;
struct usb_line6_pod *pod = line6_to_pod(line6);

switch (pod->startup_progress) {
case POD_STARTUP_VERSIONREQ:
Expand Down Expand Up @@ -328,7 +330,7 @@ static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6);

ucontrol->value.integer.value[0] = pod->monitor_level;
return 0;
Expand All @@ -339,7 +341,7 @@ static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6;
struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6);

if (ucontrol->value.integer.value[0] == pod->monitor_level)
return 0;
Expand Down Expand Up @@ -368,7 +370,7 @@ static int pod_init(struct usb_line6 *line6,
const struct usb_device_id *id)
{
int err;
struct usb_line6_pod *pod = (struct usb_line6_pod *) line6;
struct usb_line6_pod *pod = line6_to_pod(line6);

line6->process_message = line6_pod_process_message;
line6->startup = pod_startup;
Expand Down
8 changes: 5 additions & 3 deletions sound/usb/line6/podhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ struct usb_line6_podhd {
int firmware_version;
};

#define line6_to_podhd(x) container_of(x, struct usb_line6_podhd, line6)

static struct snd_ratden podhd_ratden = {
.num_min = 48000,
.num_max = 48000,
Expand Down Expand Up @@ -231,7 +233,7 @@ static int podhd_dev_start(struct usb_line6_podhd *pod)

static void podhd_startup(struct usb_line6 *line6)
{
struct usb_line6_podhd *pod = (struct usb_line6_podhd *)line6;
struct usb_line6_podhd *pod = line6_to_podhd(line6);

podhd_dev_start(pod);
line6_read_serial_number(&pod->line6, &pod->serial_number);
Expand All @@ -241,7 +243,7 @@ static void podhd_startup(struct usb_line6 *line6)

static void podhd_disconnect(struct usb_line6 *line6)
{
struct usb_line6_podhd *pod = (struct usb_line6_podhd *)line6;
struct usb_line6_podhd *pod = line6_to_podhd(line6);

if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL_INFO) {
struct usb_interface *intf;
Expand All @@ -260,7 +262,7 @@ static int podhd_init(struct usb_line6 *line6,
const struct usb_device_id *id)
{
int err;
struct usb_line6_podhd *pod = (struct usb_line6_podhd *) line6;
struct usb_line6_podhd *pod = line6_to_podhd(line6);
struct usb_interface *intf;

line6->disconnect = podhd_disconnect;
Expand Down
14 changes: 7 additions & 7 deletions sound/usb/line6/toneport.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ struct usb_line6_toneport {
struct toneport_led leds[2];
};

#define line6_to_toneport(x) container_of(x, struct usb_line6_toneport, line6)

static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);

#define TONEPORT_PCM_DELAY 1
Expand Down Expand Up @@ -211,8 +213,8 @@ static int snd_toneport_source_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
struct usb_line6_toneport *toneport =
(struct usb_line6_toneport *)line6pcm->line6;
struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6);

ucontrol->value.enumerated.item[0] = toneport->source;
return 0;
}
Expand All @@ -222,8 +224,7 @@ static int snd_toneport_source_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
struct usb_line6_toneport *toneport =
(struct usb_line6_toneport *)line6pcm->line6;
struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6);
unsigned int source;

source = ucontrol->value.enumerated.item[0];
Expand Down Expand Up @@ -397,8 +398,7 @@ static int toneport_setup(struct usb_line6_toneport *toneport)
*/
static void line6_toneport_disconnect(struct usb_line6 *line6)
{
struct usb_line6_toneport *toneport =
(struct usb_line6_toneport *)line6;
struct usb_line6_toneport *toneport = line6_to_toneport(line6);

if (toneport_has_led(toneport))
toneport_remove_leds(toneport);
Expand All @@ -412,7 +412,7 @@ static int toneport_init(struct usb_line6 *line6,
const struct usb_device_id *id)
{
int err;
struct usb_line6_toneport *toneport = (struct usb_line6_toneport *) line6;
struct usb_line6_toneport *toneport = line6_to_toneport(line6);

toneport->type = id->driver_info;

Expand Down
10 changes: 6 additions & 4 deletions sound/usb/line6/variax.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct usb_line6_variax {
int startup_progress;
};

#define line6_to_variax(x) container_of(x, struct usb_line6_variax, line6)

#define VARIAX_OFFSET_ACTIVATE 7

/*
Expand Down Expand Up @@ -86,7 +88,7 @@ static void variax_activate_async(struct usb_line6_variax *variax, int a)

static void variax_startup(struct usb_line6 *line6)
{
struct usb_line6_variax *variax = (struct usb_line6_variax *)line6;
struct usb_line6_variax *variax = line6_to_variax(line6);

switch (variax->startup_progress) {
case VARIAX_STARTUP_VERSIONREQ:
Expand Down Expand Up @@ -115,7 +117,7 @@ static void variax_startup(struct usb_line6 *line6)
*/
static void line6_variax_process_message(struct usb_line6 *line6)
{
struct usb_line6_variax *variax = (struct usb_line6_variax *) line6;
struct usb_line6_variax *variax = line6_to_variax(line6);
const unsigned char *buf = variax->line6.buffer_message;

switch (buf[0]) {
Expand Down Expand Up @@ -149,7 +151,7 @@ static void line6_variax_process_message(struct usb_line6 *line6)
*/
static void line6_variax_disconnect(struct usb_line6 *line6)
{
struct usb_line6_variax *variax = (struct usb_line6_variax *)line6;
struct usb_line6_variax *variax = line6_to_variax(line6);

kfree(variax->buffer_activate);
}
Expand All @@ -160,7 +162,7 @@ static void line6_variax_disconnect(struct usb_line6 *line6)
static int variax_init(struct usb_line6 *line6,
const struct usb_device_id *id)
{
struct usb_line6_variax *variax = (struct usb_line6_variax *) line6;
struct usb_line6_variax *variax = line6_to_variax(line6);
int err;

line6->process_message = line6_variax_process_message;
Expand Down

0 comments on commit f23a09e

Please sign in to comment.