Skip to contentSkip to conversation

ALSA: line6: constify snd_kcontrol_new structures

PATCH Applied Bhumika Goyal 3 participants 4 messages Apr 12, 2017 – Apr 13, 2017 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: line6: constify snd_kcontrol_new structures

Declare snd_kcontrol_new strcutures as const as they are only passed as an argument to the function snd_ctl_new1. This argument is of type const, so snd_kcontrol_new structures having this property can be made const too. Done using Coccinelle:

@r disable optional_qualifier@
identifier x;
position p;
@@
static struct snd_kcontrol_new x@p={...};

@ok@
identifier r.x;
position p;
@@
snd_ctl_new1(&x@p,...)

@bad@
position p != {r.p,ok.p};
identifier r.x;
@@
x@p

@depends on !bad disable optional_qualifier@
identifier r.x;
@@
+const
struct snd_kcontrol_new x;

---
 sound/usb/line6/pod.c      | 2 +-
 sound/usb/line6/toneport.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
sound/usb/line6/pod.c +1 -1
index 17aa616..358224c 100644
@@ -380,7 +380,7 @@ static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
 }
 
 /* control definition */
-static struct snd_kcontrol_new pod_control_monitor = {
+static const struct snd_kcontrol_new pod_control_monitor = {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	.name = "Monitor Playback Volume",
 	.index = 0,
sound/usb/line6/toneport.c +2 -2
index 8e22f43..ba7975c 100644
@@ -250,7 +250,7 @@ static void toneport_start_pcm(unsigned long arg)
 }
 
 /* control definition */
-static struct snd_kcontrol_new toneport_control_monitor = {
+static const struct snd_kcontrol_new toneport_control_monitor = {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	.name = "Monitor Playback Volume",
 	.index = 0,
@@ -261,7 +261,7 @@ static struct snd_kcontrol_new toneport_control_monitor = {
 };
 
 /* source selector definition */
-static struct snd_kcontrol_new toneport_control_source = {
+static const struct snd_kcontrol_new toneport_control_source = {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	.name = "PCM Capture Source",
 	.index = 0,
Signature · 1 line
2.7.4
Applied
#1 lore raw
Quoted 24 lines · Bhumika Goyal

Declare snd_kcontrol_new strcutures as const as they are only passed as an argument to the function snd_ctl_new1. This argument is of type const, so snd_kcontrol_new structures having this property can be made const too. Done using Coccinelle:

@r disable optional_qualifier@
identifier x;
position p;
@@
static struct snd_kcontrol_new x@p={...};

@ok@
identifier r.x;
position p;
@@
snd_ctl_new1(&x@p,...)

@bad@
position p != {r.p,ok.p};
identifier r.x;
@@
x@p

Quoted 7 lines

@depends on !bad disable optional_qualifier@
identifier r.x;
@@
+const
struct snd_kcontrol_new x;

Applied, thanks.

Takashi

Reviewed-by on v1 1/1
#2 lore raw
In reply to Bhumika Goyal

Hi,

Quoted 29 lines · Bhumika Goyal

Declare snd_kcontrol_new strcutures as const as they are only passed as an argument to the function snd_ctl_new1. This argument is of type const, so snd_kcontrol_new structures having this property can be made const too. Done using Coccinelle:

@r disable optional_qualifier@
identifier x;
position p;
@@
static struct snd_kcontrol_new x@p={...};

@ok@
identifier r.x;
position p;
@@
snd_ctl_new1(&x@p,...)

@bad@
position p != {r.p,ok.p};
identifier r.x;
@@
x@p

@depends on !bad disable optional_qualifier@
identifier r.x;
@@
+const
struct snd_kcontrol_new x;

Quoted 5 lines
---
 sound/usb/line6/pod.c      | 2 +-
 sound/usb/line6/toneport.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

I have interests in your way to detect this kind of issue, because below 'struct snd_kcontrol_new' array seems not to be detected. I think there's a space to improve it.

https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/tree/sound/usb/line6/pcm.c#n432

432 /* control definition */
433 static struct snd_kcontrol_new line6_controls[] = {
434 {
435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,

Later, I'll post for the above line.

Quoted 27 lines
sound/usb/line6/pod.c +1 -1
index 17aa616..358224c 100644
@@ -380,7 +380,7 @@ static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
 }
 
 /* control definition */
-static struct snd_kcontrol_new pod_control_monitor = {
+static const struct snd_kcontrol_new pod_control_monitor = {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	.name = "Monitor Playback Volume",
 	.index = 0,
sound/usb/line6/toneport.c +1 -1
index 8e22f43..ba7975c 100644
@@ -250,7 +250,7 @@ static void toneport_start_pcm(unsigned long arg)
 }
 
 /* control definition */
-static struct snd_kcontrol_new toneport_control_monitor = {
+static const struct snd_kcontrol_new toneport_control_monitor = {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	.name = "Monitor Playback Volume",
 	.index = 0,

sound/usb/line6/toneport.c static struct snd_kcontrol_new toneport_control_monitor = { · line 267

Quoted 8 lines
sound/usb/line6/toneport.c +1 -1
@@ -261,7 +261,7 @@ static struct snd_kcontrol_new toneport_control_monitor = {
 };
 
 /* source selector definition */
-static struct snd_kcontrol_new toneport_control_source = {
+static const struct snd_kcontrol_new toneport_control_source = {
 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	.name = "PCM Capture Source",
 	.index = 0,

Regards

Takashi Sakamoto

#3 lore raw
Quoted 41 lines · Takashi Sakamoto

Hi,

Quoted 30 lines · Bhumika Goyal

Declare snd_kcontrol_new strcutures as const as they are only passed as an argument to the function snd_ctl_new1. This argument is of type const, so snd_kcontrol_new structures having this property can be made const too. Done using Coccinelle:

@r disable optional_qualifier@
identifier x;
position p;
@@
static struct snd_kcontrol_new x@p={...};

@ok@
identifier r.x;
position p;
@@
snd_ctl_new1(&x@p,...)

@bad@
position p != {r.p,ok.p};
identifier r.x;
@@
x@p

@depends on !bad disable optional_qualifier@
identifier r.x;
@@
+const
struct snd_kcontrol_new x;

Quoted 5 lines
---
 sound/usb/line6/pod.c      | 2 +-
 sound/usb/line6/toneport.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
Quoted 6 lines

I have interests in your way to detect this kind of issue, because below 'struct snd_kcontrol_new' array seems not to be detected. I think there's a space to improve it.

Thanks for pointing it out. The logic that I use currently for my scripts doesn't take into account the arrays. I will extend the script for arrays too.

Thanks,
Bhumika

Quoted 53 lines

https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/tree/sound/usb/line6/pcm.c#n432

432 /* control definition */
433 static struct snd_kcontrol_new line6_controls[] = {
434 {
435 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,

Later, I'll post for the above line.

Quoted 36 lines
sound/usb/line6/pod.c +1 -1
index 17aa616..358224c 100644
@@ -380,7 +380,7 @@ static int snd_pod_control_monitor_put(struct
 snd_kcontrol *kcontrol,
 }
 
 /* control definition */
-static struct snd_kcontrol_new pod_control_monitor = {
+static const struct snd_kcontrol_new pod_control_monitor = {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name = "Monitor Playback Volume",
        .index = 0,
sound/usb/line6/toneport.c +2 -2
index 8e22f43..ba7975c 100644
@@ -250,7 +250,7 @@ static void toneport_start_pcm(unsigned long arg)
 }
 
 /* control definition */
-static struct snd_kcontrol_new toneport_control_monitor = {
+static const struct snd_kcontrol_new toneport_control_monitor = {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name = "Monitor Playback Volume",
        .index = 0,
@@ -261,7 +261,7 @@ static struct snd_kcontrol_new
 toneport_control_monitor = {
 };
 
 /* source selector definition */
-static struct snd_kcontrol_new toneport_control_source = {
+static const struct snd_kcontrol_new toneport_control_source = {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name = "PCM Capture Source",
Quoted 1 line
        .index = 0,

Regards

Takashi Sakamoto