Skip to contentSkip to conversation

ALSA: usb-audio: Use kmemdup rather than duplicating its implementation

PATCH Applied Thomas Meyer 2 participants 2 messages Nov 10, 2011 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: usb-audio: Use kmemdup rather than duplicating its implementation

Use kmemdup rather than duplicating its implementation

The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci.

---

sound/usb/quirks.c 2011-11-08 11:06:23.015258350 +0100 renamed from sound/usb/quirks.c 2011-11-07 19:38:37.987378553 +0100 +3 -4
diff -u -p a/sound/usb/quirks.c b/sound/usb/quirks.c
@@ -137,12 +137,12 @@ static int create_fixed_stream_quirk(str
 		return -ENOMEM;
 	}
 	if (fp->nr_rates > 0) {
-		rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
+		rate_table = kmemdup(fp->rate_table,
+				     sizeof(int) * fp->nr_rates, GFP_KERNEL);
 		if (!rate_table) {
 			kfree(fp);
 			return -ENOMEM;
 		}
-		memcpy(rate_table, fp->rate_table, sizeof(int) * fp->nr_rates);
 		fp->rate_table = rate_table;
 	}
 
@@ -224,10 +224,9 @@ static int create_uaxx_quirk(struct snd_
 	if (altsd->bNumEndpoints != 1)
 		return -ENXIO;
 
-	fp = kmalloc(sizeof(*fp), GFP_KERNEL);
+	fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
 	if (!fp)
 		return -ENOMEM;
-	memcpy(fp, &ua_format, sizeof(*fp));
 
 	fp->iface = altsd->bInterfaceNumber;
 	fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;

.

Applied
#1 lore raw

At Thu, 10 Nov 2011 19:38:43 +0100,

Quoted 7 lines · Thomas Meyer

Use kmemdup rather than duplicating its implementation

The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci.

Thanks, applied now.

Takashi

Quoted 34 lines

---

diff -u -p a/sound/usb/quirks.c b/sound/usb/quirks.c

sound/usb/quirks.c 2011-11-08 11:06:23.015258350 +0100 renamed from sound/usb/quirks.c 2011-11-07 19:38:37.987378553 +0100 +3 -4
@@ -137,12 +137,12 @@ static int create_fixed_stream_quirk(str
 		return -ENOMEM;
 	}
 	if (fp->nr_rates > 0) {
-		rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
+		rate_table = kmemdup(fp->rate_table,
+				     sizeof(int) * fp->nr_rates, GFP_KERNEL);
 		if (!rate_table) {
 			kfree(fp);
 			return -ENOMEM;
 		}
-		memcpy(rate_table, fp->rate_table, sizeof(int) * fp->nr_rates);
 		fp->rate_table = rate_table;
 	}
 
@@ -224,10 +224,9 @@ static int create_uaxx_quirk(struct snd_
 	if (altsd->bNumEndpoints != 1)
 		return -ENXIO;
 
-	fp = kmalloc(sizeof(*fp), GFP_KERNEL);
+	fp = kmemdup(&ua_format, sizeof(*fp), GFP_KERNEL);
 	if (!fp)
 		return -ENOMEM;
-	memcpy(fp, &ua_format, sizeof(*fp));
 
 	fp->iface = altsd->bInterfaceNumber;
 	fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;

.