Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 777a5510 authored by Julia Lawall's avatar Julia Lawall Committed by Martin Schwidefsky
Browse files

[S390] drivers/s390/char: Use kstrdup

Use kstrdup when the goal of an allocation is copy a string into the
allocated region.  Additionally drop the now unused variable len.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/

)

// <smpl>
@@
expression from,to;
expression flag,E1,E2;
statement S;
@@

-  to = kmalloc(strlen(from) + 1,flag);
+  to = kstrdup(from, flag);
   ... when != \(from = E1 \| to = E1 \)
   if (to==NULL || ...) S
   ... when != \(from = E2 \| to = E2 \)
-  strcpy(to, from);
// </smpl>

Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent ab3c68ee
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -49,7 +49,7 @@ static unsigned char ret_diacr[NR_DEAD] = {
struct kbd_data *
struct kbd_data *
kbd_alloc(void) {
kbd_alloc(void) {
	struct kbd_data *kbd;
	struct kbd_data *kbd;
	int i, len;
	int i;


	kbd = kzalloc(sizeof(struct kbd_data), GFP_KERNEL);
	kbd = kzalloc(sizeof(struct kbd_data), GFP_KERNEL);
	if (!kbd)
	if (!kbd)
@@ -72,11 +72,10 @@ kbd_alloc(void) {
		goto out_maps;
		goto out_maps;
	for (i = 0; i < ARRAY_SIZE(func_table); i++) {
	for (i = 0; i < ARRAY_SIZE(func_table); i++) {
		if (func_table[i]) {
		if (func_table[i]) {
			len = strlen(func_table[i]) + 1;
			kbd->func_table[i] = kstrdup(func_table[i],
			kbd->func_table[i] = kmalloc(len, GFP_KERNEL);
						     GFP_KERNEL);
			if (!kbd->func_table[i])
			if (!kbd->func_table[i])
				goto out_func;
				goto out_func;
			memcpy(kbd->func_table[i], func_table[i], len);
		}
		}
	}
	}
	kbd->fn_handler =
	kbd->fn_handler =