Skip to contentSkip to conversation

string: Add stracpy and stracpy_pad

PATCH Superseded Joe Perches 9 participants 42 messages Jul 23, 2019 – Jul 29, 2019

Subsystems (104)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover string: Add stracpy and stracpy_pad

Add more string copy mechanisms to help avoid defects

Joe Perches (2):
string: Add stracpy and stracpy_pad mechanisms
kernel-doc: core-api: Include string.h into core-api

 Documentation/core-api/kernel-api.rst |  3 +++
 include/linux/string.h                | 46 +++++++++++++++++++++++++++++++++--
 lib/string.c                          | 10 +++++---
 3 files changed, 53 insertions(+), 6 deletions(-)
Signature · 1 line
2.15.0
#1 lore raw

PATCH 1/2 string: Add stracpy and stracpy_pad mechanisms

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

These mechanisms verify that the to argument is an array of char or other compatible types like u8 or unsigned char.

A BUILD_BUG is emitted when the type of to is not compatible.

---
 include/linux/string.h | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
include/linux/string.h +41 -0
index 4deb11f7976b..f80b0973f0e5 100644
@@ -35,6 +35,47 @@ ssize_t strscpy(char *, const char *, size_t);
 /* Wraps calls to strscpy()/memset(), no arch specific code required */
 ssize_t strscpy_pad(char *dest, const char *src, size_t count);
 
+/**
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.
+ */
+#define stracpy(to, from)					\
+({								\
+	size_t size = ARRAY_SIZE(to);				\
+	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
+								\
+	strscpy(to, from, size);				\
+})
+
+/**
+ * stracpy_pad - Copy a C-string into an array of char with %NUL padding
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy_pad.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination
+ * and zero-pads the remaining size of @to
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.
+ */
+#define stracpy_pad(to, from)					\
+({								\
+	size_t size = ARRAY_SIZE(to);				\
+	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
+								\
+	strscpy_pad(to, from, size);				\
+})
+
 #ifndef __HAVE_ARCH_STRCAT
 extern char * strcat(char *, const char *);
 #endif
Signature · 1 line
2.15.0
maintainer
#2 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 5 lines · On Mon, 22 Jul 2019 17:38:15 -0700 Joe Perches <[email protected]> wrote:

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

Quoted 9 lines

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

These mechanisms verify that the to argument is an array of char or other compatible types like u8 or unsigned char.

A BUILD_BUG is emitted when the type of to is not compatible.

It would be nice to include some conversions. To demonstrate the need, to test the code, etc.

#3 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 11 lines · Andrew Morton
Quoted 9 lines · On Mon, 22 Jul 2019 17:38:15 -0700 Joe Perches <[email protected]> wrote:

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

Quoted 8 lines
Quoted 5 lines

These mechanisms verify that the to argument is an array of char or other compatible types like u8 or unsigned char.

A BUILD_BUG is emitted when the type of to is not compatible.

It would be nice to include some conversions. To demonstrate the need, to test the code, etc.

How about all the kernel/ ?

---
 kernel/acct.c                  | 2 +-
 kernel/cgroup/cgroup-v1.c      | 3 +--
 kernel/debug/gdbstub.c         | 4 ++--
 kernel/debug/kdb/kdb_support.c | 2 +-
 kernel/events/core.c           | 4 ++--
 kernel/module.c                | 2 +-
 kernel/printk/printk.c         | 2 +-
 kernel/time/clocksource.c      | 2 +-
 8 files changed, 10 insertions(+), 11 deletions(-)
kernel/acct.c +1 -1
index 81f9831a7859..5ad29248b654 100644
@@ -425,7 +425,7 @@ static void fill_ac(acct_t *ac)
 	memset(ac, 0, sizeof(acct_t));
 
 	ac->ac_version = ACCT_VERSION | ACCT_BYTEORDER;
-	strlcpy(ac->ac_comm, current->comm, sizeof(ac->ac_comm));
+	stracpy(ac->ac_comm, current->comm);
 
 	/* calculate run_time in nsec*/
 	run_time = ktime_get_ns();
kernel/cgroup/cgroup-v1.c +1 -2
index 88006be40ea3..dd4f041e4179 100644
@@ -571,8 +571,7 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
 	if (!cgrp)
 		return -ENODEV;
 	spin_lock(&release_agent_path_lock);
-	strlcpy(cgrp->root->release_agent_path, strstrip(buf),
-		sizeof(cgrp->root->release_agent_path));
+	stracpy(cgrp->root->release_agent_path, strstrip(buf));
 	spin_unlock(&release_agent_path_lock);
 	cgroup_kn_unlock(of->kn);
 	return nbytes;
kernel/debug/gdbstub.c +2 -2
index 4b280fc7dd67..a263f27f51ad 100644
@@ -1095,10 +1095,10 @@ int gdbstub_state(struct kgdb_state *ks, char *cmd)
 		return error;
 	case 's':
 	case 'c':
-		strscpy(remcom_in_buffer, cmd, sizeof(remcom_in_buffer));
+		stracpy(remcom_in_buffer, cmd);
 		return 0;
 	case '$':
-		strscpy(remcom_in_buffer, cmd, sizeof(remcom_in_buffer));
+		stracpy(remcom_in_buffer, cmd);
 		gdbstub_use_prev_in_buf = strlen(remcom_in_buffer);
 		gdbstub_prev_in_buf_pos = 0;
 		return 0;
kernel/debug/kdb/kdb_support.c +1 -1
index b8e6306e7e13..b49b6c3976c7 100644
@@ -192,7 +192,7 @@ int kallsyms_symbol_complete(char *prefix_name, int max_len)
 
 	while ((name = kdb_walk_kallsyms(&pos))) {
 		if (strncmp(name, prefix_name, prefix_len) == 0) {
-			strscpy(ks_namebuf, name, sizeof(ks_namebuf));
+			stracpy(ks_namebuf, name);
 			/* Work out the longest name that matches the prefix */
 			if (++number == 1) {
 				prev_len = min_t(int, max_len-1,
kernel/events/core.c +2 -2
index 026a14541a38..25bd8c777270 100644
@@ -7049,7 +7049,7 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)
 	unsigned int size;
 
 	memset(comm, 0, sizeof(comm));
-	strlcpy(comm, comm_event->task->comm, sizeof(comm));
+	stracpy(comm, comm_event->task->comm);
 	size = ALIGN(strlen(comm)+1, sizeof(u64));
 
 	comm_event->comm = comm;
@@ -7394,7 +7394,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
 	}
 
 cpy_name:
-	strlcpy(tmp, name, sizeof(tmp));
+	stracpy(tmp, name);
 	name = tmp;
 got_name:
 	/*
kernel/module.c +1 -1
index 5933395af9a0..39384b0c90b8 100644
@@ -1021,7 +1021,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
 	async_synchronize_full();
 
 	/* Store the name of the last unloaded module for diagnostic purposes */
-	strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
+	stracpy(last_unloaded_module, mod->name);
 
 	free_module(mod);
 	return 0;
kernel/printk/printk.c +1 -1
index 424abf802f02..029633052be4 100644
@@ -2127,7 +2127,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
 		return -E2BIG;
 	if (!brl_options)
 		preferred_console = i;
-	strlcpy(c->name, name, sizeof(c->name));
+	stracpy(c->name, name);
 	c->options = options;
 	braille_set_options(c, brl_options);
 
kernel/time/clocksource.c +1 -1
index fff5f64981c6..f0c833d89ace 100644
@@ -1203,7 +1203,7 @@ static int __init boot_override_clocksource(char* str)
 {
 	mutex_lock(&clocksource_mutex);
 	if (str)
-		strlcpy(override_name, str, sizeof(override_name));
+		stracpy(override_name, str);
 	mutex_unlock(&clocksource_mutex);
 	return 1;
 }
#4 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 22 lines · Joe Perches
Quoted 11 lines · Andrew Morton
Quoted 9 lines · On Mon, 22 Jul 2019 17:38:15 -0700 Joe Perches <[email protected]> wrote:

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

Quoted 8 lines
Quoted 5 lines

These mechanisms verify that the to argument is an array of char or other compatible types like u8 or unsigned char.

A BUILD_BUG is emitted when the type of to is not compatible.

It would be nice to include some conversions. To demonstrate the need, to test the code, etc.

How about all the kernel/ ?

Quoted 10 lines
---
 kernel/acct.c                  | 2 +-
 kernel/cgroup/cgroup-v1.c      | 3 +--
 kernel/debug/gdbstub.c         | 4 ++--
 kernel/debug/kdb/kdb_support.c | 2 +-
 kernel/events/core.c           | 4 ++--
 kernel/module.c                | 2 +-
 kernel/printk/printk.c         | 2 +-
 kernel/time/clocksource.c      | 2 +-
 8 files changed, 10 insertions(+), 11 deletions(-)

I think that's a good start. I still think we could just give Linus a Coccinelle script too, for the next merge window...

-Kees

Quoted 121 lines
kernel/acct.c +1 -1
index 81f9831a7859..5ad29248b654 100644
@@ -425,7 +425,7 @@ static void fill_ac(acct_t *ac)
 	memset(ac, 0, sizeof(acct_t));
 
 	ac->ac_version = ACCT_VERSION | ACCT_BYTEORDER;
-	strlcpy(ac->ac_comm, current->comm, sizeof(ac->ac_comm));
+	stracpy(ac->ac_comm, current->comm);
 
 	/* calculate run_time in nsec*/
 	run_time = ktime_get_ns();
kernel/cgroup/cgroup-v1.c +1 -2
index 88006be40ea3..dd4f041e4179 100644
@@ -571,8 +571,7 @@ static ssize_t cgroup_release_agent_write(struct kernfs_open_file *of,
 	if (!cgrp)
 		return -ENODEV;
 	spin_lock(&release_agent_path_lock);
-	strlcpy(cgrp->root->release_agent_path, strstrip(buf),
-		sizeof(cgrp->root->release_agent_path));
+	stracpy(cgrp->root->release_agent_path, strstrip(buf));
 	spin_unlock(&release_agent_path_lock);
 	cgroup_kn_unlock(of->kn);
 	return nbytes;
kernel/debug/gdbstub.c +2 -2
index 4b280fc7dd67..a263f27f51ad 100644
@@ -1095,10 +1095,10 @@ int gdbstub_state(struct kgdb_state *ks, char *cmd)
 		return error;
 	case 's':
 	case 'c':
-		strscpy(remcom_in_buffer, cmd, sizeof(remcom_in_buffer));
+		stracpy(remcom_in_buffer, cmd);
 		return 0;
 	case '$':
-		strscpy(remcom_in_buffer, cmd, sizeof(remcom_in_buffer));
+		stracpy(remcom_in_buffer, cmd);
 		gdbstub_use_prev_in_buf = strlen(remcom_in_buffer);
 		gdbstub_prev_in_buf_pos = 0;
 		return 0;
kernel/debug/kdb/kdb_support.c +1 -1
index b8e6306e7e13..b49b6c3976c7 100644
@@ -192,7 +192,7 @@ int kallsyms_symbol_complete(char *prefix_name, int max_len)
 
 	while ((name = kdb_walk_kallsyms(&pos))) {
 		if (strncmp(name, prefix_name, prefix_len) == 0) {
-			strscpy(ks_namebuf, name, sizeof(ks_namebuf));
+			stracpy(ks_namebuf, name);
 			/* Work out the longest name that matches the prefix */
 			if (++number == 1) {
 				prev_len = min_t(int, max_len-1,
kernel/events/core.c +2 -2
index 026a14541a38..25bd8c777270 100644
@@ -7049,7 +7049,7 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)
 	unsigned int size;
 
 	memset(comm, 0, sizeof(comm));
-	strlcpy(comm, comm_event->task->comm, sizeof(comm));
+	stracpy(comm, comm_event->task->comm);
 	size = ALIGN(strlen(comm)+1, sizeof(u64));
 
 	comm_event->comm = comm;
@@ -7394,7 +7394,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
 	}
 
 cpy_name:
-	strlcpy(tmp, name, sizeof(tmp));
+	stracpy(tmp, name);
 	name = tmp;
 got_name:
 	/*
kernel/module.c +1 -1
index 5933395af9a0..39384b0c90b8 100644
@@ -1021,7 +1021,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
 	async_synchronize_full();
 
 	/* Store the name of the last unloaded module for diagnostic purposes */
-	strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
+	stracpy(last_unloaded_module, mod->name);
 
 	free_module(mod);
 	return 0;
kernel/printk/printk.c +1 -1
index 424abf802f02..029633052be4 100644
@@ -2127,7 +2127,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
 		return -E2BIG;
 	if (!brl_options)
 		preferred_console = i;
-	strlcpy(c->name, name, sizeof(c->name));
+	stracpy(c->name, name);
 	c->options = options;
 	braille_set_options(c, brl_options);
 
kernel/time/clocksource.c +1 -1
index fff5f64981c6..f0c833d89ace 100644
@@ -1203,7 +1203,7 @@ static int __init boot_override_clocksource(char* str)
 {
 	mutex_lock(&clocksource_mutex);
 	if (str)
-		strlcpy(override_name, str, sizeof(override_name));
+		stracpy(override_name, str);
 	mutex_unlock(&clocksource_mutex);
 	return 1;
 }
Signature · 1 line
Kees Cook
#5 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

In reply to Joe Perches
Quoted 11 lines · Joe Perches

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

These mechanisms verify that the to argument is an array of char or other compatible types

yes

like u8 or unsigned char.

no. "unsigned char" aka u8, "signed char" aka s8 and plain char are not __builtin_types_compatible_p to one another.

Quoted 16 lines

A BUILD_BUG is emitted when the type of to is not compatible.

---
 include/linux/string.h | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
include/linux/string.h +1 -0
index 4deb11f7976b..f80b0973f0e5 100644
@@ -35,6 +35,47 @@ ssize_t strscpy(char *, const char *, size_t);
 /* Wraps calls to strscpy()/memset(), no arch specific code required */
 ssize_t strscpy_pad(char *dest, const char *src, size_t count);
 
+/**

include/linux/string.h ssize_t strscpy(char *, const char *, size_t); · line 48

Quoted 10 lines
include/linux/string.h +10 -0
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.

Well, yes, but more importantly and generally: -E2BIG if the copy including %NUL didn't fit. [The zero size array thing could be made into a build bug for these stra* variants if one thinks that might actually occur in real code.]

include/linux/string.h ssize_t strscpy(char *, const char *, size_t); · line 54

Quoted 6 lines
include/linux/string.h +6 -0
+ */
+#define stracpy(to, from)					\
+({								\
+	size_t size = ARRAY_SIZE(to);				\
+	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
+								\

ARRAY_SIZE should ensure to is indeed an array, but it doesn't hurt to spell the second condition

BUILD_BUG_ON(!__same_type(typeof(to), char[]))

(the gcc docs explicitly mention that "The type 'int[]' and 'int[5]' are compatible.) - just in case that line gets copy-pasted somewhere that doesn't have another must-be-array check nearby.

You should use a more "unique" identifier than "size". from could be some expression that refers to such a variable from the surrounding scope.

Rasmus

#6 lore raw

RE: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

From: Rasmus Villemoes

Quoted 1 line

Sent: 23 July 2019 07:56

...

Quoted 12 lines
Quoted 11 lines

+/**
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.

Quoted 4 lines

Well, yes, but more importantly and generally: -E2BIG if the copy including %NUL didn't fit. [The zero size array thing could be made into a build bug for these stra* variants if one thinks that might actually occur in real code.]

Probably better is to return the size of the destination if the copy didn't fit (zero if the buffer is zero length).
This allows code to do repeated:

	offset += str*cpy(buf + offset, src, sizeof buf - offset);

and do a final check for overflow after all the copies.

The same is true for a snprintf()like function

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#7 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

(adding Chris Metcalf)

Quoted 23 lines · David Laight

From: Rasmus Villemoes

Quoted 1 line

Sent: 23 July 2019 07:56

...

Quoted 12 lines
Quoted 11 lines

+/**
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.

Quoted 4 lines

Well, yes, but more importantly and generally: -E2BIG if the copy including %NUL didn't fit. [The zero size array thing could be made into a build bug for these stra* variants if one thinks that might actually occur in real code.]

Probably better is to return the size of the destination if the copy didn't fit (zero if the buffer is zero length).
This allows code to do repeated:

Quoted 6 lines
	offset += str*cpy(buf + offset, src, sizeof buf - offset);

and do a final check for overflow after all the copies.

The same is true for a snprintf()like function

Chris? You added this function.
Do you have an opinion here?

#8 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

In reply to David Laight
Quoted 20 lines · David Laight

From: Rasmus Villemoes

Quoted 1 line

Sent: 23 July 2019 07:56

...

Quoted 12 lines
Quoted 11 lines

+/**
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.

Quoted 4 lines

Well, yes, but more importantly and generally: -E2BIG if the copy including %NUL didn't fit. [The zero size array thing could be made into a build bug for these stra* variants if one thinks that might actually occur in real code.]

Quoted 7 lines

Probably better is to return the size of the destination if the copy didn't fit (zero if the buffer is zero length).
This allows code to do repeated:

	offset += str*cpy(buf + offset, src, sizeof buf - offset);

and do a final check for overflow after all the copies.

The same is true for a snprintf()like function

Please no; I understand the utility of the "max on error" condition for chaining, but chaining is less common than standard operations. And it requires that the size of the destination be known in multiple places, which isn't robust either.

The very point of stracpy() is to not need to know the size of the destination (i.e. it's handled by the compiler). (And it can't be chained since it requires the base address of the array, not a char *.)

Signature · 1 line
Kees Cook
#9 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

In reply to David Laight

Hi,

Quoted 25 lines · David Laight

From: Rasmus Villemoes

Quoted 1 line

Sent: 23 July 2019 07:56

...

Quoted 15 lines
Quoted 6 lines

+/**
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *

Quoted 8 lines

+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.

Quoted 6 lines

Well, yes, but more importantly and generally: -E2BIG if the copy including %NUL didn't fit. [The zero size array thing could be made into
a build bug for these stra* variants if one thinks that might actually
occur in real code.]

Quoted 9 lines

Probably better is to return the size of the destination if the copy didn't fit
(zero if the buffer is zero length).
This allows code to do repeated:

	offset += str*cpy(buf + offset, src, sizeof buf - offset);

and do a final check for overflow after all the copies.

The same is true for a snprintf()like function

Beware that snprintf(), per C standard, is supposed to return the length of the formatted string, regarless of the size of the destination buffer.

So encouraging developper to write something like code below because snprintf() in kernel behave in a non-standard way, will likely create some issues in the near future.

  for(;...;)
    offset += snprintf(buf + offset, size - offset, "......", ....);

(Reminder: the code below is not safe and shouldn't be used)

Regards.

Signature · 2 lines
Yann Droneaud
OPTEYA
#10 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 9 lines · Yann Droneaud

Hi,

Beware that snprintf(), per C standard, is supposed to return the length of the formatted string, regarless of the size of the destination buffer.

So encouraging developper to write something like code below because snprintf() in kernel behave in a non-standard way,

The kernel's snprintf() does not behave in a non-standard way, at least not with respect to its return value. It doesn't support %n or floating point, of course, and there are some quirks regarding precision (see lib/test_printf.c for details).

There's the non-standard scnprintf() for getting the length of the formatted string, which can safely be used in an append loop. Or one can use the seq_buf API.

Rasmus

#11 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 3 lines · Rasmus Villemoes

The kernel's snprintf() does not behave in a non-standard way, at least not with respect to its return value.

Note that the kernels snprintf() *does* very much protect against the overflow case - not by changing the return value, but simply by having

/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
if (WARN_ON_ONCE(size > INT_MAX))
return 0;

at the very top.

So you can't actually overflow in the kernel by using the repeated

        offset += vsnprintf( .. size - offset ..);

model.

Yes, it's the wrong thing to do, but it is still _safe_.

Linus

#12 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 16 lines · Linus Torvalds
Quoted 3 lines · Rasmus Villemoes

The kernel's snprintf() does not behave in a non-standard way, at least not with respect to its return value.

Note that the kernels snprintf() *does* very much protect against the overflow case - not by changing the return value, but simply by having

/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
if (WARN_ON_ONCE(size > INT_MAX))
return 0;

at the very top.

Quoted 7 lines

So you can't actually overflow in the kernel by using the repeated

        offset += vsnprintf( .. size - offset ..);

model.

Yes, it's the wrong thing to do, but it is still _safe_.

Actually, perhaps we should add this test to strscpy() too?

lib/string.c +1 -1
index 461fb620f85f..0e0d7628ddc4 100644
@@ -182,7 +182,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
 	size_t max = count;
 	long res = 0;
 
-	if (count == 0)
+	if (count == 0 || count > INT_MAX)
 		return -E2BIG;
 
 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
Signature · 1 line
Kees Cook
#13 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 18 lines · Kees Cook
Quoted 17 lines · Linus Torvalds
Quoted 2 lines · Rasmus Villemoes

The kernel's snprintf() does not behave in a non-standard way, at least not with respect to its return value.

Note that the kernels snprintf() *does* very much protect against the overflow case - not by changing the return value, but simply by having

/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
if (WARN_ON_ONCE(size > INT_MAX))
return 0;

at the very top.

So you can't actually overflow in the kernel by using the repeated

Quoted 7 lines
Quoted 5 lines
        offset += vsnprintf( .. size - offset ..);

model.

Yes, it's the wrong thing to do, but it is still _safe_.

Actually, perhaps we should add this test to strscpy() too?

Doesn't seem to have a reason not to be added but maybe it's better to add another WARN_ON_ONCE.

lib/string.c

Quoted 1 line
lib/string.c +0 -0

[]

Quoted 10 lines
lib/string.c +1 -1
@@ -182,7 +182,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
 	size_t max = count;
 	long res = 0;
 
-	if (count == 0)
+	if (count == 0 || count > INT_MAX)
 		return -E2BIG;
 
 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
#14 lore raw

PATCH 1/2 string: Add stracpy and stracpy_pad mechanisms]

In reply to Joe Perches

Hello Julia.

I just sent a patch to add yet another string copy mechanism.

This could help avoid misuses of strscpy and strlcpy like this patch set:

https://lore.kernel.org/lkml/[email protected]/T/

A possible cocci script to do conversions could be:

   $ cat str.cpy.cocci
   @@
   expression e1;
   expression e2;
   @@

- strscpy(e1, e2, sizeof(e1))
+ stracpy(e1, e2)

@@
expression e1;
expression e2;
@@

- strlcpy(e1, e2, sizeof(e1))
+ stracpy(e1, e2)

This obviously does not match the style of all the scripts/coccinelle cocci files, but this might be something that could be added improved and added.

This script produces:

$ spatch --in-place -sp-file str.cpy.cocci .
$ git checkout tools/
$ git diff --shortstat
 958 files changed, 2179 insertions(+), 2655 deletions(-)

The remainder of strlcpy and strscpy uses in the
kernel would generally have a form like:

strlcpy(to, from, DEFINE)

where DEFINE is the specified size of to

Could the cocci script above be updated to find
and correct those styles as well?

cheers, Joe

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

These mechanisms verify that the to argument is an array of char or other compatible types like u8 or unsigned char.

A BUILD_BUG is emitted when the type of to is not compatible.

---
 include/linux/string.h | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
include/linux/string.h +41 -0
index 4deb11f7976b..f80b0973f0e5 100644
@@ -35,6 +35,47 @@ ssize_t strscpy(char *, const char *, size_t);
 /* Wraps calls to strscpy()/memset(), no arch specific code required */
 ssize_t strscpy_pad(char *dest, const char *src, size_t count);
 
+/**
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.
+ */
+#define stracpy(to, from)					\
+({								\
+	size_t size = ARRAY_SIZE(to);				\
+	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
+								\
+	strscpy(to, from, size);				\
+})
+
+/**
+ * stracpy_pad - Copy a C-string into an array of char with %NUL padding
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy_pad.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination
+ * and zero-pads the remaining size of @to
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.
+ */
+#define stracpy_pad(to, from)					\
+({								\
+	size_t size = ARRAY_SIZE(to);				\
+	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
+								\
+	strscpy_pad(to, from, size);				\
+})
+
 #ifndef __HAVE_ARCH_STRCAT
 extern char * strcat(char *, const char *);
 #endif
Signature · 1 line
2.15.0

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#15 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 42 lines · Joe Perches

Hello Julia.

I just sent a patch to add yet another string copy mechanism.

This could help avoid misuses of strscpy and strlcpy like this patch set:

https://lore.kernel.org/lkml/[email protected]/T/

A possible cocci script to do conversions could be:

   $ cat str.cpy.cocci
   @@
   expression e1;
   expression e2;
   @@

- strscpy(e1, e2, sizeof(e1))
+ stracpy(e1, e2)

   @@
   expression e1;
   expression e2;
   @@

   - strlcpy(e1, e2, sizeof(e1))
   + stracpy(e1, e2)

This obviously does not match the style of all the scripts/coccinelle cocci files, but this might be something that could be added improved and added.

This script produces:

$ spatch --in-place -sp-file str.cpy.cocci .
$ git checkout tools/
$ git diff --shortstat
 958 files changed, 2179 insertions(+), 2655 deletions(-)

The remainder of strlcpy and strscpy uses in the kernel would generally have a form like:

Quoted 6 lines

strlcpy(to, from, DEFINE)

where DEFINE is the specified size of to

Could the cocci script above be updated to find and correct those styles as well?

I guess it would depend on what "to" is and what DEFINE expands into. For example, in cpuidle-powernv.c, I see:

strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);

and by poking around I see:

struct cpuidle_state {
	char		name[CPUIDLE_NAME_LEN];
	char		desc[CPUIDLE_DESC_LEN];
	...
};

So I guess this case is ok.

I will look into it.

thanks,
julia

#16 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 53 lines · Julia Lawall
Quoted 40 lines · Joe Perches

I just sent a patch to add yet another string copy mechanism.

This could help avoid misuses of strscpy and strlcpy like this patch set:

https://lore.kernel.org/lkml/[email protected]/T/

A possible cocci script to do conversions could be:

   $ cat str.cpy.cocci
   @@
   expression e1;
   expression e2;
   @@

- strscpy(e1, e2, sizeof(e1))
+ stracpy(e1, e2)

   @@
   expression e1;
   expression e2;
   @@

   - strlcpy(e1, e2, sizeof(e1))
   + stracpy(e1, e2)

This obviously does not match the style of all the scripts/coccinelle cocci files, but this might be something that could be added improved and added.

This script produces:

$ spatch --in-place -sp-file str.cpy.cocci .
$ git checkout tools/
$ git diff --shortstat
 958 files changed, 2179 insertions(+), 2655 deletions(-)

The remainder of strlcpy and strscpy uses in the kernel would generally have a form like:

Quoted 6 lines

strlcpy(to, from, DEFINE)

where DEFINE is the specified size of to

Could the cocci script above be updated to find and correct those styles as well?

I guess it would depend on what "to" is and what DEFINE expands into. For example, in cpuidle-powernv.c, I see:

strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);

Quoted 7 lines

and by poking around I see:

struct cpuidle_state {
	char		name[CPUIDLE_NAME_LEN];
	char		desc[CPUIDLE_DESC_LEN];
	...
};

Yes, ideally this case would not modify the #define for the length but adapt the strlcpy(,,DEFINE)

There are a lot of these in drivers/hwmon using I2C_NAME_SIZE.

Quoted 1 line

I will look into it.

Thanks.

#17 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

A seantic patch and the resulting output for the case where the third arugument is a constant is attached. Likewise the resulting output on a recent linux-next.

julia

// spatch.opt -j 44 ~/linux-next stracpy.cocci --all-includes --include-headers-for-types --very-quiet > stracpy.out

@r@
identifier f,i1,i2;
struct i1 e1;
expression e2;
position p;
@@
\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

@@
identifier r.i1,r.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

@@
identifier f,i2;
expression e1,e2;
position r.p;
@@
(
-strscpy
+stracpy
|
-strlcpy
+stracpy
)(e1.f, e2
- , i2
)@p

// ---------------------------------

@r1@
struct i1 *e1;
expression e2;
identifier f,i1,i2;
position p;
@@
\(strscpy\|strlcpy\)(e1->f, e2, i2)@p

@@
identifier r1.i1,r1.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

@@
identifier f,i2;
expression e1,e2;
position r1.p;
@@
(
-strscpy
+stracpy
|
-strlcpy
+stracpy
)(e1->f, e2
- , i2
)@p

drivers/cpuidle/cpuidle-powernv.c +2 -2
diff -u -p a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
@@ -236,8 +236,8 @@ static inline void add_powernv_state(int
 				     unsigned int exit_latency,
 				     u64 psscr_val, u64 psscr_mask)
 {
-	strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);
-	strlcpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN);
+	stracpy(powernv_states[index].name, name);
+	stracpy(powernv_states[index].desc, name);
 	powernv_states[index].flags = flags;
 	powernv_states[index].target_residency = target_residency;
 	powernv_states[index].exit_latency = exit_latency;
arch/mips/bcm47xx/board.c +1 -2
diff -u -p a/arch/mips/bcm47xx/board.c b/arch/mips/bcm47xx/board.c
@@ -344,8 +344,7 @@ void __init bcm47xx_board_detect(void)
 
 	board_detected = bcm47xx_board_get_nvram();
 	bcm47xx_board.board = board_detected->board;
-	strlcpy(bcm47xx_board.name, board_detected->name,
-		BCM47XX_BOARD_MAX_NAME);
+	stracpy(bcm47xx_board.name, board_detected->name);
 }
 
 enum bcm47xx_board bcm47xx_board_get(void)
crypto/api.c +1 -1
diff -u -p a/crypto/api.c b/crypto/api.c
@@ -115,7 +115,7 @@ struct crypto_larval *crypto_larval_allo
 	larval->alg.cra_priority = -1;
 	larval->alg.cra_destroy = crypto_larval_destroy;
 
-	strlcpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME);
+	stracpy(larval->alg.cra_name, name);
 	init_completion(&larval->completion);
 
 	return larval;
drivers/s390/char/hmcdrv_cache.c +1 -2
diff -u -p a/drivers/s390/char/hmcdrv_cache.c b/drivers/s390/char/hmcdrv_cache.c
@@ -154,8 +154,7 @@ static ssize_t hmcdrv_cache_do(const str
 		/* cache some file info (FTP command, file name and file
 		 * size) unconditionally
 		 */
-		strlcpy(hmcdrv_cache_file.fname, ftp->fname,
-			HMCDRV_FTP_FIDENT_MAX);
+		stracpy(hmcdrv_cache_file.fname, ftp->fname);
 		hmcdrv_cache_file.id = ftp->id;
 		pr_debug("caching cmd %d, file size %zu for '%s'\n",
 			 ftp->id, hmcdrv_cache_file.fsize, ftp->fname);
sound/ppc/keywest.c +1 -1
diff -u -p a/sound/ppc/keywest.c b/sound/ppc/keywest.c
@@ -48,7 +48,7 @@ static int keywest_attach_adapter(struct
 		return -EINVAL; /* ignored */
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strlcpy(info.type, "keywest", I2C_NAME_SIZE);
+	stracpy(info.type, "keywest");
 	info.addr = keywest_ctx->addr;
 	keywest_ctx->client = i2c_new_device(adapter, &info);
 	if (!keywest_ctx->client)
drivers/media/pci/saa7164/saa7164-dvb.c +5 -5
diff -u -p a/drivers/media/pci/saa7164/saa7164-dvb.c b/drivers/media/pci/saa7164/saa7164-dvb.c
@@ -110,7 +110,7 @@ static int si2157_attach(struct saa7164_
 
 	memset(&bi, 0, sizeof(bi));
 
-	strscpy(bi.type, "si2157", I2C_NAME_SIZE);
+	stracpy(bi.type, "si2157");
 	bi.platform_data = cfg;
 	bi.addr = addr8bit >> 1;
 
@@ -633,7 +633,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2168_config.fe = &port->dvb.frontend;
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0xc8 >> 1;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -653,7 +653,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2157_config.if_port = 1;
 			si2157_config.fe = port->dvb.frontend;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0xc0 >> 1;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
@@ -678,7 +678,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2168_config.fe = &port->dvb.frontend;
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0xcc >> 1;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -698,7 +698,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2157_config.fe = port->dvb.frontend;
 			si2157_config.if_port = 1;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0xc0 >> 1;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
drivers/media/usb/dvb-usb-v2/af9035.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -189,7 +189,7 @@ static int af9035_add_i2c_dev(struct dvb
 		.platform_data = platform_data,
 	};
 
-	strscpy(board_info.type, type, I2C_NAME_SIZE);
+	stracpy(board_info.type, type);
 
 	/* find first free client */
 	for (num = 0; num < AF9035_I2C_CLIENT_MAX; num++) {
drivers/media/pci/smipcie/smipcie-main.c +4 -4
diff -u -p a/drivers/media/pci/smipcie/smipcie-main.c b/drivers/media/pci/smipcie/smipcie-main.c
@@ -540,7 +540,7 @@ static int smi_dvbsky_m88ds3103_fe_attac
 	}
 	/* attach tuner */
 	ts2020_config.fe = port->fe;
-	strscpy(tuner_info.type, "ts2020", I2C_NAME_SIZE);
+	stracpy(tuner_info.type, "ts2020");
 	tuner_info.addr = 0x60;
 	tuner_info.platform_data = &ts2020_config;
 	tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info);
@@ -596,7 +596,7 @@ static int smi_dvbsky_m88rs6000_fe_attac
 	}
 	/* attach tuner */
 	m88rs6000t_config.fe = port->fe;
-	strscpy(tuner_info.type, "m88rs6000t", I2C_NAME_SIZE);
+	stracpy(tuner_info.type, "m88rs6000t");
 	tuner_info.addr = 0x21;
 	tuner_info.platform_data = &m88rs6000t_config;
 	tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info);
@@ -638,7 +638,7 @@ static int smi_dvbsky_sit2_fe_attach(str
 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
 
 	memset(&client_info, 0, sizeof(struct i2c_board_info));
-	strscpy(client_info.type, "si2168", I2C_NAME_SIZE);
+	stracpy(client_info.type, "si2168");
 	client_info.addr = 0x64;
 	client_info.platform_data = &si2168_config;
 
@@ -655,7 +655,7 @@ static int smi_dvbsky_sit2_fe_attach(str
 	si2157_config.if_port = 1;
 
 	memset(&client_info, 0, sizeof(struct i2c_board_info));
-	strscpy(client_info.type, "si2157", I2C_NAME_SIZE);
+	stracpy(client_info.type, "si2157");
 	client_info.addr = 0x60;
 	client_info.platform_data = &si2157_config;
 
drivers/media/usb/dvb-usb/dib0700_devices.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/dib0700_devices.c b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -3760,7 +3760,7 @@ static int xbox_one_attach(struct dvb_us
 	mn88472_config.ts_mode = PARALLEL_TS_MODE;
 	mn88472_config.ts_clock = FIXED_TS_CLOCK;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "mn88472", I2C_NAME_SIZE);
+	stracpy(info.type, "mn88472");
 	info.addr = 0x18;
 	info.platform_data = &mn88472_config;
 	request_module(info.type);
@@ -3787,7 +3787,7 @@ static int xbox_one_attach(struct dvb_us
 	tda18250_config.fe = adap->fe_adap[0].fe;
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "tda18250", I2C_NAME_SIZE);
+	stracpy(info.type, "tda18250");
 	info.addr = 0x60;
 	info.platform_data = &tda18250_config;
 
drivers/media/pci/bt8xx/bttv-i2c.c +1 -1
diff -u -p a/drivers/media/pci/bt8xx/bttv-i2c.c b/drivers/media/pci/bt8xx/bttv-i2c.c
@@ -335,7 +335,7 @@ static void do_i2c_scan(char *name, stru
 /* init + register i2c adapter */
 int init_bttv_i2c(struct bttv *btv)
 {
-	strscpy(btv->i2c_client.name, "bttv internal", I2C_NAME_SIZE);
+	stracpy(btv->i2c_client.name, "bttv internal");
 
 	if (i2c_hw)
 		btv->use_i2c_hw = 1;
drivers/media/usb/dvb-usb-v2/rtl28xxu.c +9 -9
diff -u -p a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -693,7 +693,7 @@ static int rtl2831u_frontend_attach(stru
 
 	/* attach demodulator */
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
+	stracpy(board_info.type, "rtl2830");
 	board_info.addr = 0x10;
 	board_info.platform_data = pdata;
 	request_module("%s", board_info.type);
@@ -914,7 +914,7 @@ static int rtl2832u_frontend_attach(stru
 
 	/* attach demodulator */
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
+	stracpy(board_info.type, "rtl2832");
 	board_info.addr = 0x10;
 	board_info.platform_data = pdata;
 	request_module("%s", board_info.type);
@@ -953,7 +953,7 @@ static int rtl2832u_frontend_attach(stru
 
 			mn88472_config.fe = &adap->fe[1];
 			mn88472_config.i2c_wr_max = 22,
-			strscpy(info.type, "mn88472", I2C_NAME_SIZE);
+			stracpy(info.type, "mn88472");
 			mn88472_config.xtal = 20500000;
 			mn88472_config.ts_mode = SERIAL_TS_MODE;
 			mn88472_config.ts_clock = VARIABLE_TS_CLOCK;
@@ -978,7 +978,7 @@ static int rtl2832u_frontend_attach(stru
 
 			mn88473_config.fe = &adap->fe[1];
 			mn88473_config.i2c_wr_max = 22,
-			strscpy(info.type, "mn88473", I2C_NAME_SIZE);
+			stracpy(info.type, "mn88473");
 			info.addr = 0x18;
 			info.platform_data = &mn88473_config;
 			request_module(info.type);
@@ -1021,7 +1021,7 @@ static int rtl2832u_frontend_attach(stru
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			si2168_config.ts_clock_inv = false;
 			si2168_config.ts_clock_gapped = true;
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0x64;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -1212,7 +1212,7 @@ static int rtl2832u_tuner_attach(struct
 				.clock = 28800000,
 			};
 
-			strscpy(info.type, "e4000", I2C_NAME_SIZE);
+			stracpy(info.type, "e4000");
 			info.addr = 0x64;
 			info.platform_data = &e4000_config;
 
@@ -1236,7 +1236,7 @@ static int rtl2832u_tuner_attach(struct
 			};
 			struct i2c_board_info board_info = {};
 
-			strscpy(board_info.type, "fc2580", I2C_NAME_SIZE);
+			stracpy(board_info.type, "fc2580");
 			board_info.addr = 0x56;
 			board_info.platform_data = &fc2580_pdata;
 			request_module("fc2580");
@@ -1267,7 +1267,7 @@ static int rtl2832u_tuner_attach(struct
 		if (ret)
 			goto err;
 
-		strscpy(board_info.type, "tua9001", I2C_NAME_SIZE);
+		stracpy(board_info.type, "tua9001");
 		board_info.addr = 0x60;
 		board_info.platform_data = &tua9001_pdata;
 		request_module("tua9001");
@@ -1312,7 +1312,7 @@ static int rtl2832u_tuner_attach(struct
 				.inversion = false,
 			};
 
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0x60;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
net/sched/sch_teql.c +1 -1
diff -u -p a/net/sched/sch_teql.c b/net/sched/sch_teql.c
@@ -489,7 +489,7 @@ static int __init teql_init(void)
 
 		master = netdev_priv(dev);
 
-		strlcpy(master->qops.id, dev->name, IFNAMSIZ);
+		stracpy(master->qops.id, dev->name);
 		err = register_qdisc(&master->qops);
 
 		if (err) {
drivers/net/ethernet/qlogic/qede/qede_main.c +1 -1
diff -u -p a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c
@@ -1094,7 +1094,7 @@ static int __qede_probe(struct pci_dev *
 	sp_params.drv_minor = QEDE_MINOR_VERSION;
 	sp_params.drv_rev = QEDE_REVISION_VERSION;
 	sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
-	strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
+	stracpy(sp_params.name, "qede LAN");
 	rc = qed_ops->common->slowpath_start(cdev, &sp_params);
 	if (rc) {
 		pr_notice("Cannot start slowpath\n");
drivers/staging/greybus/audio_module.c +1 -1
diff -u -p a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c
@@ -341,7 +341,7 @@ static int gb_audio_probe(struct gb_bund
 	/* inform above layer for uevent */
 	dev_dbg(dev, "Inform set_event:%d to above layer\n", 1);
 	/* prepare for the audio manager */
-	strlcpy(desc.name, gbmodule->name, GB_AUDIO_MANAGER_MODULE_NAME_LEN);
+	stracpy(desc.name, gbmodule->name);
 	desc.vid = 2; /* todo */
 	desc.pid = 3; /* todo */
 	desc.intf_id = gbmodule->dev_id;
net/core/dev.c +1 -1
diff -u -p a/net/core/dev.c b/net/core/dev.c
@@ -572,7 +572,7 @@ static int netdev_boot_setup_add(char *n
 	for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
 		if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
 			memset(s[i].name, 0, sizeof(s[i].name));
-			strlcpy(s[i].name, name, IFNAMSIZ);
+			stracpy(s[i].name, name);
 			memcpy(&s[i].map, map, sizeof(s[i].map));
 			break;
 		}
drivers/media/pci/ivtv/ivtv-i2c.c +2 -2
diff -u -p a/drivers/media/pci/ivtv/ivtv-i2c.c b/drivers/media/pci/ivtv/ivtv-i2c.c
@@ -206,7 +206,7 @@ static int ivtv_i2c_new_ir(struct ivtv *
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.platform_data = init_data;
-	strscpy(info.type, type, I2C_NAME_SIZE);
+	stracpy(info.type, type);
 
 	return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
 	       -1 : 0;
@@ -234,7 +234,7 @@ struct i2c_client *ivtv_i2c_new_ir_legac
 	};
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 	return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL);
 }
 
drivers/media/usb/dvb-usb/cxusb.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
@@ -1406,7 +1406,7 @@ static int cxusb_mygica_t230_frontend_at
 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
 	si2168_config.ts_clock_inv = 1;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "si2168", I2C_NAME_SIZE);
+	stracpy(info.type, "si2168");
 	info.addr = 0x64;
 	info.platform_data = &si2168_config;
 	request_module(info.type);
@@ -1426,7 +1426,7 @@ static int cxusb_mygica_t230_frontend_at
 	si2157_config.fe = adap->fe_adap[0].fe;
 	si2157_config.if_port = 1;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "si2157", I2C_NAME_SIZE);
+	stracpy(info.type, "si2157");
 	info.addr = 0x60;
 	info.platform_data = &si2157_config;
 	request_module(info.type);
drivers/net/macvlan.c +1 -1
diff -u -p a/drivers/net/macvlan.c b/drivers/net/macvlan.c
@@ -827,7 +827,7 @@ static int macvlan_do_ioctl(struct net_d
 	struct ifreq ifrr;
 	int err = -EOPNOTSUPP;
 
-	strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
+	stracpy(ifrr.ifr_name, real_dev->name);
 	ifrr.ifr_ifru = ifr->ifr_ifru;
 
 	switch (cmd) {
tools/perf/util/machine.c +2 -2
diff -u -p a/tools/perf/util/machine.c b/tools/perf/util/machine.c
@@ -1078,7 +1078,7 @@ int machine__map_x86_64_entry_trampoline
 			.pgoff = pgoff,
 		};
 
-		strlcpy(xm.name, ENTRY_TRAMPOLINE_NAME, KMAP_NAME_LEN);
+		stracpy(xm.name, ENTRY_TRAMPOLINE_NAME);
 
 		if (machine__create_extra_kernel_map(machine, kernel, &xm) < 0)
 			return -1;
@@ -1542,7 +1542,7 @@ static int machine__process_extra_kernel
 	if (kernel == NULL)
 		return -1;
 
-	strlcpy(xm.name, event->mmap.filename, KMAP_NAME_LEN);
+	stracpy(xm.name, event->mmap.filename);
 
 	return machine__create_extra_kernel_map(machine, kernel, &xm);
 }
drivers/macintosh/therm_windtunnel.c +2 -2
diff -u -p a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
@@ -320,10 +320,10 @@ do_attach( struct i2c_adapter *adapter )
 		struct i2c_board_info info;
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
-		strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE);
+		stracpy(info.type, "therm_ds1775");
 		i2c_new_probed_device(adapter, &info, scan_ds1775, NULL);
 
-		strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE);
+		stracpy(info.type, "therm_adm1030");
 		i2c_new_probed_device(adapter, &info, scan_adm1030, NULL);
 
 		if( x.thermostat && x.fan ) {
drivers/media/pci/cx88/cx88-input.c +2 -2
diff -u -p a/drivers/media/pci/cx88/cx88-input.c b/drivers/media/pci/cx88/cx88-input.c
@@ -600,7 +600,7 @@ void cx88_i2c_init_ir(struct cx88_core *
 		return;
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (core->boardnr) {
 	case CX88_BOARD_LEADTEK_PVR2000:
@@ -625,7 +625,7 @@ void cx88_i2c_init_ir(struct cx88_core *
 
 		if (*addrp == 0x71) {
 			/* Hauppauge Z8F0811 */
-			strscpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE);
+			stracpy(info.type, "ir_z8f0811_haup");
 			core->init_data.name = core->board.name;
 			core->init_data.ir_codes = RC_MAP_HAUPPAUGE;
 			core->init_data.type = RC_PROTO_BIT_RC5 |
sound/aoa/codecs/tas.c +1 -1
diff -u -p a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
@@ -894,7 +894,7 @@ static int tas_i2c_probe(struct i2c_clie
 	/* seems that half is a saner default */
 	tas->drc_range = TAS3004_DRC_MAX / 2;
 
-	strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN);
+	stracpy(tas->codec.name, "tas");
 	tas->codec.owner = THIS_MODULE;
 	tas->codec.init = tas_init_codec;
 	tas->codec.exit = tas_exit_codec;
drivers/mfd/htc-i2cpld.c +1 -1
diff -u -p a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c
@@ -351,7 +351,7 @@ static int htcpld_register_chip_i2c(
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.addr = plat_chip_data->addr;
-	strlcpy(info.type, "htcpld-chip", I2C_NAME_SIZE);
+	stracpy(info.type, "htcpld-chip");
 	info.platform_data = chip;
 
 	/* Add the I2C device.  This calls the probe() function. */
drivers/platform/x86/intel_cht_int33fe.c +3 -3
diff -u -p a/drivers/platform/x86/intel_cht_int33fe.c b/drivers/platform/x86/intel_cht_int33fe.c
@@ -285,7 +285,7 @@ cht_int33fe_register_max17047(struct dev
 	}
 
 	memset(&board_info, 0, sizeof(board_info));
-	strlcpy(board_info.type, "max17047", I2C_NAME_SIZE);
+	stracpy(board_info.type, "max17047");
 	board_info.dev_name = "max17047";
 	board_info.fwnode = fwnode;
 	data->max17047 = i2c_acpi_new_device(dev, 1, &board_info);
@@ -374,7 +374,7 @@ static int cht_int33fe_probe(struct plat
 	}
 
 	memset(&board_info, 0, sizeof(board_info));
-	strlcpy(board_info.type, "typec_fusb302", I2C_NAME_SIZE);
+	stracpy(board_info.type, "typec_fusb302");
 	board_info.dev_name = "fusb302";
 	board_info.fwnode = fwnode;
 	board_info.irq = fusb302_irq;
@@ -394,7 +394,7 @@ static int cht_int33fe_probe(struct plat
 	memset(&board_info, 0, sizeof(board_info));
 	board_info.dev_name = "pi3usb30532";
 	board_info.fwnode = fwnode;
-	strlcpy(board_info.type, "pi3usb30532", I2C_NAME_SIZE);
+	stracpy(board_info.type, "pi3usb30532");
 
 	data->pi3usb30532 = i2c_acpi_new_device(dev, 3, &board_info);
 	if (IS_ERR(data->pi3usb30532)) {
tools/perf/arch/x86/util/machine.c +1 -1
diff -u -p a/tools/perf/arch/x86/util/machine.c b/tools/perf/arch/x86/util/machine.c
@@ -39,7 +39,7 @@ static int add_extra_kernel_map(struct e
 	mi->maps[mi->cnt].start = start;
 	mi->maps[mi->cnt].end   = end;
 	mi->maps[mi->cnt].pgoff = pgoff;
-	strlcpy(mi->maps[mi->cnt].name, name, KMAP_NAME_LEN);
+	stracpy(mi->maps[mi->cnt].name, name);
 
 	mi->cnt += 1;
 
drivers/media/usb/tm6000/tm6000-i2c.c +1 -1
diff -u -p a/drivers/media/usb/tm6000/tm6000-i2c.c b/drivers/media/usb/tm6000/tm6000-i2c.c
@@ -300,7 +300,7 @@ int tm6000_i2c_register(struct tm6000_co
 		return rc;
 
 	dev->i2c_client.adapter = &dev->i2c_adap;
-	strscpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE);
+	stracpy(dev->i2c_client.name, "tm6000 internal");
 	tm6000_i2c_eeprom(dev);
 
 	return 0;
drivers/media/pci/cx23885/cx23885-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx23885/cx23885-i2c.c b/drivers/media/pci/cx23885/cx23885-i2c.c
@@ -334,7 +334,7 @@ int cx23885_i2c_register(struct cx23885_
 		};
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
-		strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_video");
 		/* Use quick read command for probe, some IR chips don't
 		 * support writes */
 		i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
drivers/staging/comedi/comedi_fops.c +2 -2
diff -u -p a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
@@ -937,8 +937,8 @@ static int do_devinfo_ioctl(struct comed
 	/* fill devinfo structure */
 	devinfo.version_code = COMEDI_VERSION_CODE;
 	devinfo.n_subdevs = dev->n_subdevices;
-	strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN);
-	strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN);
+	stracpy(devinfo.driver_name, dev->driver->driver_name);
+	stracpy(devinfo.board_name, dev->board_name);
 
 	s = comedi_file_read_subdevice(file);
 	if (s)
drivers/i2c/busses/i2c-i801.c +3 -3
diff -u -p a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
@@ -1134,7 +1134,7 @@ static void dmi_check_onboard_device(u8
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		info.addr = dmi_devices[i].i2c_addr;
-		strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
+		stracpy(info.type, dmi_devices[i].i2c_type);
 		i2c_new_device(adap, &info);
 		break;
 	}
@@ -1279,7 +1279,7 @@ static void register_dell_lis3lv02d_i2c_
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.addr = dell_lis3lv02d_devices[i].i2c_addr;
-	strlcpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
+	stracpy(info.type, "lis3lv02d");
 	i2c_new_device(&priv->adapter, &info);
 }
 
@@ -1295,7 +1295,7 @@ static void i801_probe_optional_slaves(s
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		info.addr = apanel_addr;
-		strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
+		stracpy(info.type, "fujitsu_apanel");
 		i2c_new_device(&priv->adapter, &info);
 	}
 
drivers/media/usb/dvb-usb-v2/zd1301.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/zd1301.c b/drivers/media/usb/dvb-usb-v2/zd1301.c
@@ -168,7 +168,7 @@ static int zd1301_frontend_attach(struct
 	dev->mt2060_pdata.i2c_write_max = 9;
 	dev->mt2060_pdata.dvb_frontend = frontend;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "mt2060", I2C_NAME_SIZE);
+	stracpy(board_info.type, "mt2060");
 	board_info.addr = 0x60;
 	board_info.platform_data = &dev->mt2060_pdata;
 	request_module("%s", "mt2060");
drivers/s390/block/dasd_eer.c +2 -4
diff -u -p a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
@@ -313,8 +313,7 @@ static void dasd_eer_write_standard_trig
 	ktime_get_real_ts64(&ts);
 	header.tv_sec = ts.tv_sec;
 	header.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
-	strlcpy(header.busid, dev_name(&device->cdev->dev),
-		DASD_EER_BUSID_SIZE);
+	stracpy(header.busid, dev_name(&device->cdev->dev));
 
 	spin_lock_irqsave(&bufferlock, flags);
 	list_for_each_entry(eerb, &bufferlist, list) {
@@ -356,8 +355,7 @@ static void dasd_eer_write_snss_trigger(
 	ktime_get_real_ts64(&ts);
 	header.tv_sec = ts.tv_sec;
 	header.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
-	strlcpy(header.busid, dev_name(&device->cdev->dev),
-		DASD_EER_BUSID_SIZE);
+	stracpy(header.busid, dev_name(&device->cdev->dev));
 
 	spin_lock_irqsave(&bufferlock, flags);
 	list_for_each_entry(eerb, &bufferlist, list) {
drivers/media/pci/cx88/cx88-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx88/cx88-i2c.c b/drivers/media/pci/cx88/cx88-i2c.c
@@ -137,7 +137,7 @@ int cx88_i2c_init(struct cx88_core *core
 	i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev);
 	core->i2c_adap.algo_data = &core->i2c_algo;
 	core->i2c_client.adapter = &core->i2c_adap;
-	strscpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE);
+	stracpy(core->i2c_client.name, "cx88xx internal");
 
 	cx8800_bit_setscl(core, 1);
 	cx8800_bit_setsda(core, 1);
drivers/media/usb/cx231xx/cx231xx-input.c +1 -1
diff -u -p a/drivers/media/usb/cx231xx/cx231xx-input.c b/drivers/media/usb/cx231xx/cx231xx-input.c
@@ -67,7 +67,7 @@ int cx231xx_ir_init(struct cx231xx *dev)
 
 	dev->init_data.name = cx231xx_boards[dev->model].name;
 
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 	info.platform_data = &dev->init_data;
 
 	/*
net/ipv4/ip_tunnel.c +1 -1
diff -u -p a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
@@ -1054,7 +1054,7 @@ int ip_tunnel_init_net(struct net *net,
 
 	memset(&parms, 0, sizeof(parms));
 	if (devname)
-		strlcpy(parms.name, devname, IFNAMSIZ);
+		stracpy(parms.name, devname);
 
 	rtnl_lock();
 	itn->fb_tunnel_dev = __ip_tunnel_create(net, ops, &parms);
arch/powerpc/platforms/powernv/idle.c +1 -2
diff -u -p a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
@@ -1311,8 +1311,7 @@ static int pnv_parse_cpuidle_dt(void)
 		goto out;
 	}
 	for (i = 0; i < nr_idle_states; i++)
-		strlcpy(pnv_idle_states[i].name, temp_string[i],
-			PNV_IDLE_NAME_LEN);
+		stracpy(pnv_idle_states[i].name, temp_string[i]);
 	nr_pnv_idle_states = nr_idle_states;
 	rc = 0;
 out:
drivers/media/pci/saa7134/saa7134-input.c +1 -1
diff -u -p a/drivers/media/pci/saa7134/saa7134-input.c b/drivers/media/pci/saa7134/saa7134-input.c
@@ -856,7 +856,7 @@ void saa7134_probe_i2c_ir(struct saa7134
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	memset(&dev->init_data, 0, sizeof(dev->init_data));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (dev->board) {
 	case SAA7134_BOARD_PINNACLE_PCTV_110i:
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +3 -5
diff -u -p a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
@@ -383,13 +383,11 @@ static void brcmf_mp_attach(void)
 	 * if not set then if available use the platform data version. To make
 	 * sure it gets initialized at all, always copy the module param version
 	 */
-	strlcpy(brcmf_mp_global.firmware_path, brcmf_firmware_path,
-		BRCMF_FW_ALTPATH_LEN);
+	stracpy(brcmf_mp_global.firmware_path, brcmf_firmware_path);
 	if ((brcmfmac_pdata) && (brcmfmac_pdata->fw_alternative_path) &&
 	    (brcmf_mp_global.firmware_path[0] == '\0')) {
-		strlcpy(brcmf_mp_global.firmware_path,
-			brcmfmac_pdata->fw_alternative_path,
-			BRCMF_FW_ALTPATH_LEN);
+		stracpy(brcmf_mp_global.firmware_path,
+			brcmfmac_pdata->fw_alternative_path);
 	}
 }
 
lib/earlycpio.c +1 -1
diff -u -p a/lib/earlycpio.c b/lib/earlycpio.c
@@ -126,7 +126,7 @@ struct cpio_data find_cpio_data(const ch
 				"File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
 				p, MAX_CPIO_FILE_NAME);
 			}
-			strlcpy(cd.name, p + mypathsize, MAX_CPIO_FILE_NAME);
+			stracpy(cd.name, p + mypathsize);
 
 			cd.data = (void *)dptr;
 			cd.size = ch[C_FILESIZE];
sound/aoa/codecs/onyx.c +1 -1
diff -u -p a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
@@ -1011,7 +1011,7 @@ static int onyx_i2c_probe(struct i2c_cli
 		goto fail;
 	}
 
-	strlcpy(onyx->codec.name, "onyx", MAX_CODEC_NAME_LEN);
+	stracpy(onyx->codec.name, "onyx");
 	onyx->codec.owner = THIS_MODULE;
 	onyx->codec.init = onyx_init_codec;
 	onyx->codec.exit = onyx_exit_codec;
drivers/usb/usbip/stub_main.c +1 -1
diff -u -p a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
@@ -101,7 +101,7 @@ static int add_match_busid(char *busid)
 	for (i = 0; i < MAX_BUSID; i++) {
 		spin_lock(&busid_table[i].busid_lock);
 		if (!busid_table[i].name[0]) {
-			strlcpy(busid_table[i].name, busid, BUSID_SIZE);
+			stracpy(busid_table[i].name, busid);
 			if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
 			    (busid_table[i].status != STUB_BUSID_REMOV))
 				busid_table[i].status = STUB_BUSID_ADDED;
drivers/media/dvb-frontends/ts2020.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
@@ -516,7 +516,7 @@ struct dvb_frontend *ts2020_attach(struc
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "ts2020", I2C_NAME_SIZE);
+	stracpy(board_info.type, "ts2020");
 	board_info.addr = config->tuner_address;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(i2c, &board_info);
drivers/media/pci/cx18/cx18-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx18/cx18-i2c.c b/drivers/media/pci/cx18/cx18-i2c.c
@@ -74,7 +74,7 @@ static int cx18_i2c_new_ir(struct cx18 *
 	unsigned short addr_list[2] = { addr, I2C_CLIENT_END };
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, type, I2C_NAME_SIZE);
+	stracpy(info.type, type);
 
 	/* Our default information for ir-kbd-i2c.c to use */
 	switch (hw) {
drivers/scsi/qedi/qedi_main.c +1 -1
diff -u -p a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
@@ -2460,7 +2460,7 @@ static int __qedi_probe(struct pci_dev *
 	sp_params.drv_minor = QEDI_DRIVER_MINOR_VER;
 	sp_params.drv_rev = QEDI_DRIVER_REV_VER;
 	sp_params.drv_eng = QEDI_DRIVER_ENG_VER;
-	strlcpy(sp_params.name, "qedi iSCSI", QED_DRV_VER_STR_SIZE);
+	stracpy(sp_params.name, "qedi iSCSI");
 	rc = qedi_ops->common->slowpath_start(qedi->cdev, &sp_params);
 	if (rc) {
 		QEDI_ERR(&qedi->dbg_ctx, "Cannot start slowpath\n");
drivers/media/pci/cx23885/cx23885-dvb.c +27 -27

216 lines not on this page · raw message

drivers/s390/scsi/zfcp_fc.c +1 -2
diff -u -p a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
@@ -882,8 +882,7 @@ static void zfcp_fc_rspn(struct zfcp_ada
 	zfcp_fc_ct_ns_init(&rspn_req->ct_hdr, FC_NS_RSPN_ID,
 			   FC_SYMBOLIC_NAME_SIZE);
 	hton24(rspn_req->rspn.fr_fid.fp_fid, fc_host_port_id(shost));
-	len = strlcpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost),
-		      FC_SYMBOLIC_NAME_SIZE);
+	len = stracpy(rspn_req->rspn.fr_name, fc_host_symbolic_name(shost));
 	rspn_req->rspn.fr_name_len = len;
 
 	sg_init_one(&fc_req->sg_req, rspn_req, sizeof(*rspn_req));
drivers/media/dvb-frontends/m88ds3103.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c
@@ -1274,7 +1274,7 @@ struct dvb_frontend *m88ds3103_attach(co
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
+	stracpy(board_info.type, "m88ds3103");
 	board_info.addr = cfg->i2c_addr;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(i2c, &board_info);
drivers/media/pci/bt8xx/bttv-input.c +1 -1
diff -u -p a/drivers/media/pci/bt8xx/bttv-input.c b/drivers/media/pci/bt8xx/bttv-input.c
@@ -373,7 +373,7 @@ void init_bttv_i2c_ir(struct bttv *btv)
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	memset(&btv->init_data, 0, sizeof(btv->init_data));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (btv->c.type) {
 	case BTTV_BOARD_PV951:
drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c +2 -2
diff -u -p a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
@@ -561,7 +561,7 @@ static void pvr2_i2c_register_ir(struct
 		/* IR Receiver */
 		info.addr          = 0x18;
 		info.platform_data = init_data;
-		strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_video");
 		pvr2_trace(PVR2_TRACE_INFO, "Binding %s to i2c address 0x%02x.",
 			   info.type, info.addr);
 		i2c_new_device(&hdw->i2c_adap, &info);
@@ -576,7 +576,7 @@ static void pvr2_i2c_register_ir(struct
 		/* IR Transceiver */
 		info.addr = 0x71;
 		info.platform_data = init_data;
-		strscpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_z8f0811_haup");
 		pvr2_trace(PVR2_TRACE_INFO, "Binding %s to i2c address 0x%02x.",
 			   info.type, info.addr);
 		i2c_new_device(&hdw->i2c_adap, &info);
drivers/scsi/bfa/bfa_fcs_lport.c +4 -4
diff -u -p a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -2655,8 +2655,8 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_
 	bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
 	hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
 
-	strlcpy(hba_attr->node_sym_name.symname,
-		port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
+	stracpy(hba_attr->node_sym_name.symname,
+		port->port_cfg.node_sym_name.symname);
 	strcpy(hba_attr->vendor_info, "QLogic");
 	hba_attr->num_ports =
 		cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
@@ -2740,8 +2740,8 @@ bfa_fcs_fdmi_get_portattr(struct bfa_fcs
 	port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
 	port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
 
-	strlcpy(port_attr->port_sym_name.symname,
-		bfa_fcs_lport_get_psym_name(port).symname, BFA_SYMNAME_MAXLEN);
+	stracpy(port_attr->port_sym_name.symname,
+		bfa_fcs_lport_get_psym_name(port).symname);
 	bfa_fcs_lport_get_attr(port, &lport_attr);
 	port_attr->port_type = cpu_to_be32(lport_attr.port_type);
 	port_attr->scos = pport_attr.cos_supported;
drivers/target/target_core_configfs.c +1 -1
diff -u -p a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
@@ -618,7 +618,7 @@ static void dev_set_t10_wwn_model_alias(
 	 * here without potentially breaking existing setups, so continue to
 	 * truncate one byte shorter than what can be carried in INQUIRY.
 	 */
-	strlcpy(dev->t10_wwn.model, configname, INQUIRY_MODEL_LEN);
+	stracpy(dev->t10_wwn.model, configname);
 }
 
 static ssize_t emulate_model_alias_store(struct config_item *item,
drivers/media/usb/dvb-usb/dw2102.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
@@ -1586,7 +1586,7 @@ static int tt_s2_4600_frontend_attach(st
 	m88ds3103_pdata.lnb_hv_pol = 1;
 	m88ds3103_pdata.lnb_en_pol = 0;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
+	stracpy(board_info.type, "m88ds3103");
 	board_info.addr = 0x68;
 	board_info.platform_data = &m88ds3103_pdata;
 	request_module("m88ds3103");
@@ -1605,7 +1605,7 @@ static int tt_s2_4600_frontend_attach(st
 	/* attach tuner */
 	ts2020_config.fe = adap->fe_adap[0].fe;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "ts2022", I2C_NAME_SIZE);
+	stracpy(board_info.type, "ts2022");
 	board_info.addr = 0x60;
 	board_info.platform_data = &ts2020_config;
 	request_module("ts2020");
drivers/s390/char/sclp_ftp.c +1 -2
diff -u -p a/drivers/s390/char/sclp_ftp.c b/drivers/s390/char/sclp_ftp.c
@@ -114,8 +114,7 @@ static int sclp_ftp_et7(const struct hmc
 	sccb->evbuf.mdd.ftp.length = ftp->len;
 	sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);
 
-	len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
-		      HMCDRV_FTP_FIDENT_MAX);
+	len = stracpy(sccb->evbuf.mdd.ftp.fident, ftp->fname);
 	if (len >= HMCDRV_FTP_FIDENT_MAX) {
 		rc = -EINVAL;
 		goto out_free;
drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c +1 -2
diff -u -p a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
@@ -733,8 +733,7 @@ brcmf_fw_alloc_request(u32 chip, u32 chi
 		fwnames[j].path[0] = '\0';
 		/* check if firmware path is provided by module parameter */
 		if (brcmf_mp_global.firmware_path[0] != '\0') {
-			strlcpy(fwnames[j].path, mp_path,
-				BRCMF_FW_NAME_LEN);
+			stracpy(fwnames[j].path, mp_path);
 
 			if (end != '/') {
 				strlcat(fwnames[j].path, "/",
drivers/net/netconsole.c +4 -4
diff -u -p a/drivers/net/netconsole.c b/drivers/net/netconsole.c
@@ -177,7 +177,7 @@ static struct netconsole_target *alloc_p
 		goto fail;
 
 	nt->np.name = "netconsole";
-	strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
+	stracpy(nt->np.dev_name, "eth0");
 	nt->np.local_port = 6665;
 	nt->np.remote_port = 6666;
 	eth_broadcast_addr(nt->np.remote_mac);
@@ -413,7 +413,7 @@ static ssize_t dev_name_store(struct con
 		return -EINVAL;
 	}
 
-	strlcpy(nt->np.dev_name, buf, IFNAMSIZ);
+	stracpy(nt->np.dev_name, buf);
 
 	/* Get rid of possible trailing newline from echo(1) */
 	len = strnlen(nt->np.dev_name, IFNAMSIZ);
@@ -629,7 +629,7 @@ static struct config_item *make_netconso
 		return ERR_PTR(-ENOMEM);
 
 	nt->np.name = "netconsole";
-	strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
+	stracpy(nt->np.dev_name, "eth0");
 	nt->np.local_port = 6665;
 	nt->np.remote_port = 6666;
 	eth_broadcast_addr(nt->np.remote_mac);
@@ -707,7 +707,7 @@ restart:
 		if (nt->np.dev == dev) {
 			switch (event) {
 			case NETDEV_CHANGENAME:
-				strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ);
+				stracpy(nt->np.dev_name, dev->name);
 				break;
 			case NETDEV_RELEASE:
 			case NETDEV_JOIN:
drivers/media/usb/dvb-usb-v2/anysee.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/anysee.c b/drivers/media/usb/dvb-usb-v2/anysee.c
@@ -629,7 +629,7 @@ static int anysee_add_i2c_dev(struct dvb
 		.platform_data = platform_data,
 	};
 
-	strscpy(board_info.type, type, I2C_NAME_SIZE);
+	stracpy(board_info.type, type);
 
 	/* find first free client */
 	for (num = 0; num < ANYSEE_I2C_CLIENT_MAX; num++) {
drivers/platform/x86/i2c-multi-instantiate.c +1 -1
diff -u -p a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c
@@ -91,7 +91,7 @@ static int i2c_multi_inst_probe(struct p
 
 	for (i = 0; i < multi->num_clients && inst_data[i].type; i++) {
 		memset(&board_info, 0, sizeof(board_info));
-		strlcpy(board_info.type, inst_data[i].type, I2C_NAME_SIZE);
+		stracpy(board_info.type, inst_data[i].type);
 		snprintf(name, sizeof(name), "%s-%s.%d", match->id,
 			 inst_data[i].type, i);
 		board_info.dev_name = name;
drivers/media/dvb-frontends/cxd2820r_core.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -527,7 +527,7 @@ struct dvb_frontend *cxd2820r_attach(con
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "cxd2820r", I2C_NAME_SIZE);
+	stracpy(board_info.type, "cxd2820r");
 	board_info.addr = config->i2c_address;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(adapter, &board_info);
#18 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 5 lines · Julia Lawall

A seantic patch and the resulting output for the case where the third arugument is a constant is attached. Likewise the resulting output on a recent linux-next.

julia

Nice. Thanks Julia

A couple issues:

There is a problem with conversions with assignments of strlcpy() so ideally the cocci script should make sure any return value was not used before conversion.

This is not a provably good conversion:

drivers/s390/char/sclp_ftp.c
@@ -114,8 +114,7 @@ static int sclp_ftp_et7(const struct hmc

        sccb->evbuf.mdd.ftp.length = ftp->len;
        sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);

- len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
- HMCDRV_FTP_FIDENT_MAX);
+ len = stracpy(sccb->evbuf.mdd.ftp.fident, ftp->fname);

And:

I would have expected the bit below to find and convert uses like

	drivers/hwmon/adc128d818.c:     strlcpy(info->type, "adc128d818", I2C_NAME_SIZE);

but it seems none of those were converted.

I don't know why.

//------------------------------------------
@r1@
struct i1 *e1;
expression e2;
identifier f,i1,i2;
position p;
@@
\(strscpy\|strlcpy\)(e1->f, e2, i2)@p

@@
identifier r1.i1,r1.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

@@
identifier f,i2;
expression e1,e2;
position r1.p;
@@
(
-strscpy
+stracpy
|
-strlcpy
+stracpy
)(e1->f, e2
- , i2
)@p
//------------------------------------------

to find

#19 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 19 lines · Joe Perches
Quoted 5 lines · Julia Lawall

A seantic patch and the resulting output for the case where the third arugument is a constant is attached. Likewise the resulting output on a recent linux-next.

julia

Nice. Thanks Julia

A couple issues:

There is a problem with conversions with assignments of strlcpy() so ideally the cocci script should make sure any return value was not used before conversion.

This is not a provably good conversion:

drivers/s390/char/sclp_ftp.c

drivers/s390/char/sclp_ftp.c static int sclp_ftp_et7(const struct hmc · line 117

Quoted 6 lines
drivers/s390/char/sclp_ftp.c +1 -2
@@ -114,8 +114,7 @@ static int sclp_ftp_et7(const struct hmc
        sccb->evbuf.mdd.ftp.length = ftp->len;
        sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);
 
-       len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
-                     HMCDRV_FTP_FIDENT_MAX);
+       len = stracpy(sccb->evbuf.mdd.ftp.fident, ftp->fname);

Sorry, I don't understand the issue here. What specifically should I be looking for?

Quoted 6 lines

And:

I would have expected the bit below to find and convert uses like

	drivers/hwmon/adc128d818.c:     strlcpy(info->type, "adc128d818", I2C_NAME_SIZE);

but it seems none of those were converted.

OK, thanks. I will check on it.

julia

Quoted 36 lines

I don't know why.

//------------------------------------------
@r1@
struct i1 *e1;
expression e2;
identifier f,i1,i2;
position p;
@@
\(strscpy\|strlcpy\)(e1->f, e2, i2)@p

@@
identifier r1.i1,r1.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

@@
identifier f,i2;
expression e1,e2;
position r1.p;
@@
(

(quoted diff) +1 -1
-strscpy
+stracpy

|

(quoted diff) +1 -1
-strlcpy
+stracpy

)(e1->f, e2
- , i2
)@p
//------------------------------------------

to find

#20 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 25 lines · Julia Lawall
Quoted 22 lines · Joe Perches
Quoted 5 lines · Julia Lawall

A seantic patch and the resulting output for the case where the third arugument is a constant is attached. Likewise the resulting output on a recent linux-next.

julia

Nice. Thanks Julia

A couple issues:

There is a problem with conversions with assignments of strlcpy() so ideally the cocci script should make sure any return value was not used before conversion.

This is not a provably good conversion:

drivers/s390/char/sclp_ftp.c

drivers/s390/char/sclp_ftp.c +0 -0
@@ -114,8 +114,7 @@ static int sclp_ftp_et7(const struct hmc
        sccb->evbuf.mdd.ftp.length = ftp->len;
        sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);
 
Quoted 6 lines

drivers/s390/char/sclp_ftp.c static int sclp_ftp_et7(const struct hmc · line 117

Quoted 3 lines
drivers/s390/char/sclp_ftp.c +1 -2
-       len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
-                     HMCDRV_FTP_FIDENT_MAX);
+       len = stracpy(sccb->evbuf.mdd.ftp.fident, ftp->fname);

Sorry, I don't understand the issue here. What specifically should I be looking for?

The return value of strlcpy differs from (strscpy or stracpy).

strlcpy returns the length of the src string
str[sa]cpy returns the length of the src string if it fits in dest
or -E2BIG if src is truncated by the size of dest or -E2BIG if dest is 0 length

Any use of the strlcpy return value should not be converted because the logic after an assignment or use of the return value can not be assured to have the same behavior.

Quoted 7 lines
Quoted 5 lines

And:

I would have expected the bit below to find and convert uses like

	drivers/hwmon/adc128d818.c:     strlcpy(info->type, "adc128d818", I2C_NAME_SIZE);

but it seems none of those were converted.

OK, thanks. I will check on it.

Thanks again.

Quoted 37 lines

julia

Quoted 35 lines

I don't know why.

//------------------------------------------
@r1@
struct i1 *e1;
expression e2;
identifier f,i1,i2;
position p;
@@
\(strscpy\|strlcpy\)(e1->f, e2, i2)@p

@@
identifier r1.i1,r1.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

@@
identifier f,i2;
expression e1,e2;
position r1.p;
@@
(

(quoted diff) +2 -2
-strscpy
+stracpy
-strlcpy
+stracpy

)(e1->f, e2
- , i2
)@p
//------------------------------------------

to find

#21 lore raw

RE: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

From: Joe Perches

Quoted 36 lines

Sent: 24 July 2019 05:38

Quoted 25 lines · Julia Lawall
Quoted 22 lines · Joe Perches
Quoted 5 lines · Julia Lawall

A seantic patch and the resulting output for the case where the third arugument is a constant is attached. Likewise the resulting output on a recent linux-next.

julia

Nice. Thanks Julia

A couple issues:

There is a problem with conversions with assignments of strlcpy() so ideally the cocci script should make sure any return value was not used before conversion.

This is not a provably good conversion:

drivers/s390/char/sclp_ftp.c

drivers/s390/char/sclp_ftp.c +0 -0
@@ -114,8 +114,7 @@ static int sclp_ftp_et7(const struct hmc
        sccb->evbuf.mdd.ftp.length = ftp->len;
        sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);
 
Quoted 6 lines

drivers/s390/char/sclp_ftp.c static int sclp_ftp_et7(const struct hmc · line 117

Quoted 3 lines
drivers/s390/char/sclp_ftp.c +1 -2
-       len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
-                     HMCDRV_FTP_FIDENT_MAX);
+       len = stracpy(sccb->evbuf.mdd.ftp.fident, ftp->fname);

Sorry, I don't understand the issue here. What specifically should I be looking for?

The return value of strlcpy differs from (strscpy or stracpy).

Quoted 8 lines

strlcpy returns the length of the src string
str[sa]cpy returns the length of the src string if it fits in dest
or -E2BIG if src is truncated by the size of dest or -E2BIG if dest is 0 length

Any use of the strlcpy return value should not be converted because the logic after an assignment or use of the return value can not be assured to have the same behavior.

Most of the code probably expects the length to be that copied (so is broken if the string is truncated).

OTOH the code almost certainly doesn't expect -E2BIG either so will go wrong in that case as well.

The return value from str[as]cpy() is its own set of bugs just waiting to happen.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#22 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 8 lines · David Laight

From: Joe Perches

Quoted 7 lines

Sent: 24 July 2019 05:38

Quoted 5 lines · Julia Lawall
Quoted 4 lines · Joe Perches
Quoted 3 lines · Julia Lawall

A seantic patch and the resulting output for the case where the third arugument is a constant is attached. Likewise the resulting output on a recent linux-next.

[]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

There is a problem with conversions with assignments of strlcpy() so ideally the cocci script should make sure any return value was not used before conversion.

This is not a provably good conversion:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/s390/char/sclp_ftp.c static int sclp_ftp_et7(const struct hmc · line 117

Quoted 8 lines

drivers/s390/char/sclp_ftp.c

drivers/s390/char/sclp_ftp.c +1 -2
@@ -114,8 +114,7 @@ static int sclp_ftp_et7(const struct hmc
        sccb->evbuf.mdd.ftp.length = ftp->len;
        sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);
 
-       len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
-                     HMCDRV_FTP_FIDENT_MAX);
+       len = stracpy(sccb->evbuf.mdd.ftp.fident, ftp->fname);

[]

Quoted 6 lines
Quoted 3 lines

Any use of the strlcpy return value should not be converted because the logic after an assignment or use of the return value can not be assured to have the same behavior.

Most of the code probably expects the length to be that copied (so is broken if the string is truncated).

Fortunately there are relatively few uses of the return value of strlcpy so it's not a large problem set.

Slightly unrepresentative counts:

$ git grep -P "^\s+strlcpy\b" | wc -l
1681
$ git grep -P "=\s*strlcpy\b" | wc -l
28
#23 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 35 lines · Joe Perches
Quoted 8 lines · David Laight

From: Joe Perches

Quoted 7 lines

Sent: 24 July 2019 05:38

Quoted 5 lines · Julia Lawall
Quoted 4 lines · Joe Perches
Quoted 3 lines · Julia Lawall

A seantic patch and the resulting output for the case where the third arugument is a constant is attached. Likewise the resulting output on a recent linux-next.

[]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

There is a problem with conversions with assignments of strlcpy() so ideally the cocci script should make sure any return value was not used before conversion.

This is not a provably good conversion:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/s390/char/sclp_ftp.c static int sclp_ftp_et7(const struct hmc · line 117

Quoted 8 lines

drivers/s390/char/sclp_ftp.c

drivers/s390/char/sclp_ftp.c +1 -2
@@ -114,8 +114,7 @@ static int sclp_ftp_et7(const struct hmc
        sccb->evbuf.mdd.ftp.length = ftp->len;
        sccb->evbuf.mdd.ftp.bufaddr = virt_to_phys(ftp->buf);
 
-       len = strlcpy(sccb->evbuf.mdd.ftp.fident, ftp->fname,
-                     HMCDRV_FTP_FIDENT_MAX);
+       len = stracpy(sccb->evbuf.mdd.ftp.fident, ftp->fname);

[]

Quoted 6 lines
Quoted 3 lines

Any use of the strlcpy return value should not be converted because the logic after an assignment or use of the return value can not be assured to have the same behavior.

Most of the code probably expects the length to be that copied (so is broken if the string is truncated).

Fortunately there are relatively few uses of the return value of strlcpy so it's not a large problem set.

Quoted 6 lines

Slightly unrepresentative counts:

$ git grep -P "^\s+strlcpy\b" | wc -l
1681
$ git grep -P "=\s*strlcpy\b" | wc -l
28

OK, it's easy to check for in any case. Thanks.

julia

#24 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

In reply to Joe Perches

New version. I check for non-use of the return value of strlcpy and address some issues that affected the matching of the case where the first argument involves a pointer dereference. Actually, an isomorphism now takes care of that case, so it doesn't show up in the semantic patch explicitly any more.

julia

drivers/hwmon/lm90.c +1 -1
diff -u -p a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
@@ -1610,7 +1610,7 @@ static int lm90_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/net/netconsole.c +4 -4
diff -u -p a/drivers/net/netconsole.c b/drivers/net/netconsole.c
@@ -177,7 +177,7 @@ static struct netconsole_target *alloc_p
 		goto fail;
 
 	nt->np.name = "netconsole";
-	strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
+	stracpy(nt->np.dev_name, "eth0");
 	nt->np.local_port = 6665;
 	nt->np.remote_port = 6666;
 	eth_broadcast_addr(nt->np.remote_mac);
@@ -413,7 +413,7 @@ static ssize_t dev_name_store(struct con
 		return -EINVAL;
 	}
 
-	strlcpy(nt->np.dev_name, buf, IFNAMSIZ);
+	stracpy(nt->np.dev_name, buf);
 
 	/* Get rid of possible trailing newline from echo(1) */
 	len = strnlen(nt->np.dev_name, IFNAMSIZ);
@@ -629,7 +629,7 @@ static struct config_item *make_netconso
 		return ERR_PTR(-ENOMEM);
 
 	nt->np.name = "netconsole";
-	strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
+	stracpy(nt->np.dev_name, "eth0");
 	nt->np.local_port = 6665;
 	nt->np.remote_port = 6666;
 	eth_broadcast_addr(nt->np.remote_mac);
@@ -707,7 +707,7 @@ restart:
 		if (nt->np.dev == dev) {
 			switch (event) {
 			case NETDEV_CHANGENAME:
-				strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ);
+				stracpy(nt->np.dev_name, dev->name);
 				break;
 			case NETDEV_RELEASE:
 			case NETDEV_JOIN:
drivers/scsi/qla4xxx/ql4_os.c +5 -8
diff -u -p a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
@@ -767,10 +767,8 @@ static int qla4xxx_get_chap_list(struct
 			continue;
 
 		chap_rec->chap_tbl_idx = i;
-		strlcpy(chap_rec->username, chap_table->name,
-			ISCSI_CHAP_AUTH_NAME_MAX_LEN);
-		strlcpy(chap_rec->password, chap_table->secret,
-			QL4_CHAP_MAX_SECRET_LEN);
+		stracpy(chap_rec->username, chap_table->name);
+		stracpy(chap_rec->password, chap_table->secret);
 		chap_rec->password_length = chap_table->secret_len;
 
 		if (chap_table->flags & BIT_7) /* local */
@@ -6265,8 +6263,8 @@ static void qla4xxx_get_param_ddb(struct
 
 	tddb->tpgt = sess->tpgt;
 	tddb->port = conn->persistent_port;
-	strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
-	strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
+	stracpy(tddb->iscsi_name, sess->targetname);
+	stracpy(tddb->ip_addr, conn->persistent_address);
 }
 
 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
@@ -7769,8 +7767,7 @@ static int qla4xxx_sysfs_ddb_logout(stru
 		goto exit_ddb_logout;
 	}
 
-	strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
-		ISCSI_NAME_SIZE);
+	stracpy(flash_tddb->iscsi_name, fnode_sess->targetname);
 
 	if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
 		sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
tools/perf/util/machine.c +3 -3
diff -u -p a/tools/perf/util/machine.c b/tools/perf/util/machine.c
@@ -988,7 +988,7 @@ int machine__create_extra_kernel_map(str
 	kmap = map__kmap(map);
 
 	kmap->kmaps = &machine->kmaps;
-	strlcpy(kmap->name, xm->name, KMAP_NAME_LEN);
+	stracpy(kmap->name, xm->name);
 
 	map_groups__insert(&machine->kmaps, map);
 
@@ -1078,7 +1078,7 @@ int machine__map_x86_64_entry_trampoline
 			.pgoff = pgoff,
 		};
 
-		strlcpy(xm.name, ENTRY_TRAMPOLINE_NAME, KMAP_NAME_LEN);
+		stracpy(xm.name, ENTRY_TRAMPOLINE_NAME);
 
 		if (machine__create_extra_kernel_map(machine, kernel, &xm) < 0)
 			return -1;
@@ -1542,7 +1542,7 @@ static int machine__process_extra_kernel
 	if (kernel == NULL)
 		return -1;
 
-	strlcpy(xm.name, event->mmap.filename, KMAP_NAME_LEN);
+	stracpy(xm.name, event->mmap.filename);
 
 	return machine__create_extra_kernel_map(machine, kernel, &xm);
 }
arch/mips/bcm47xx/board.c +1 -2
diff -u -p a/arch/mips/bcm47xx/board.c b/arch/mips/bcm47xx/board.c
@@ -344,8 +344,7 @@ void __init bcm47xx_board_detect(void)
 
 	board_detected = bcm47xx_board_get_nvram();
 	bcm47xx_board.board = board_detected->board;
-	strlcpy(bcm47xx_board.name, board_detected->name,
-		BCM47XX_BOARD_MAX_NAME);
+	stracpy(bcm47xx_board.name, board_detected->name);
 }
 
 enum bcm47xx_board bcm47xx_board_get(void)
drivers/hwmon/adm1031.c +1 -1
diff -u -p a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
@@ -986,7 +986,7 @@ static int adm1031_detect(struct i2c_cli
 		return -ENODEV;
 	name = (id == 0x30) ? "adm1030" : "adm1031";
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/w83781d.c +1 -1
diff -u -p a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
@@ -1171,7 +1171,7 @@ w83781d_detect(struct i2c_client *client
 	if (isa)
 		mutex_unlock(&isa->update_lock);
 
-	strlcpy(info->type, client_name, I2C_NAME_SIZE);
+	stracpy(info->type, client_name);
 
 	return 0;
 
drivers/s390/block/dasd_eer.c +2 -4
diff -u -p a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
@@ -313,8 +313,7 @@ static void dasd_eer_write_standard_trig
 	ktime_get_real_ts64(&ts);
 	header.tv_sec = ts.tv_sec;
 	header.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
-	strlcpy(header.busid, dev_name(&device->cdev->dev),
-		DASD_EER_BUSID_SIZE);
+	stracpy(header.busid, dev_name(&device->cdev->dev));
 
 	spin_lock_irqsave(&bufferlock, flags);
 	list_for_each_entry(eerb, &bufferlist, list) {
@@ -356,8 +355,7 @@ static void dasd_eer_write_snss_trigger(
 	ktime_get_real_ts64(&ts);
 	header.tv_sec = ts.tv_sec;
 	header.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
-	strlcpy(header.busid, dev_name(&device->cdev->dev),
-		DASD_EER_BUSID_SIZE);
+	stracpy(header.busid, dev_name(&device->cdev->dev));
 
 	spin_lock_irqsave(&bufferlock, flags);
 	list_for_each_entry(eerb, &bufferlist, list) {
drivers/firmware/arm_scmi/sensors.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
@@ -146,7 +146,7 @@ static int scmi_sensor_description_get(c
 			/* Sign extend to a full s8 */
 			if (s->scale & SENSOR_SCALE_SIGN)
 				s->scale |= SENSOR_SCALE_EXTEND;
-			strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE);
+			stracpy(s->name, buf->desc[cnt].name);
 		}
 
 		desc_index += num_returned;
drivers/hwmon/adt7475.c +1 -1
diff -u -p a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
@@ -1337,7 +1337,7 @@ static int adt7475_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/w83l785ts.c +1 -1
diff -u -p a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
@@ -158,7 +158,7 @@ static int w83l785ts_detect(struct i2c_c
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "w83l785ts", I2C_NAME_SIZE);
+	stracpy(info->type, "w83l785ts");
 
 	return 0;
 }
drivers/media/dvb-core/dvbdev.c +2 -2
diff -u -p a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
@@ -975,9 +975,9 @@ struct i2c_client *dvb_module_probe(cons
 		return NULL;
 
 	if (name)
-		strscpy(board_info->type, name, I2C_NAME_SIZE);
+		stracpy(board_info->type, name);
 	else
-		strscpy(board_info->type, module_name, I2C_NAME_SIZE);
+		stracpy(board_info->type, module_name);
 
 	board_info->addr = addr;
 	board_info->platform_data = platform_data;
drivers/scsi/qedi/qedi_main.c +1 -1
diff -u -p a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
@@ -2460,7 +2460,7 @@ static int __qedi_probe(struct pci_dev *
 	sp_params.drv_minor = QEDI_DRIVER_MINOR_VER;
 	sp_params.drv_rev = QEDI_DRIVER_REV_VER;
 	sp_params.drv_eng = QEDI_DRIVER_ENG_VER;
-	strlcpy(sp_params.name, "qedi iSCSI", QED_DRV_VER_STR_SIZE);
+	stracpy(sp_params.name, "qedi iSCSI");
 	rc = qedi_ops->common->slowpath_start(qedi->cdev, &sp_params);
 	if (rc) {
 		QEDI_ERR(&qedi->dbg_ctx, "Cannot start slowpath\n");
kernel/relay.c +2 -2
diff -u -p a/kernel/relay.c b/kernel/relay.c
@@ -589,7 +589,7 @@ struct rchan *relay_open(const char *bas
 	chan->private_data = private_data;
 	if (base_filename) {
 		chan->has_base_filename = 1;
-		strlcpy(chan->base_filename, base_filename, NAME_MAX);
+		stracpy(chan->base_filename, base_filename);
 	}
 	setup_callbacks(chan, cb);
 	kref_init(&chan->kref);
@@ -660,7 +660,7 @@ int relay_late_setup_files(struct rchan
 	if (!chan || !base_filename)
 		return -EINVAL;
 
-	strlcpy(chan->base_filename, base_filename, NAME_MAX);
+	stracpy(chan->base_filename, base_filename);
 
 	mutex_lock(&relay_channels_mutex);
 	/* Is chan already set up? */
drivers/hwmon/adt7462.c +1 -1
diff -u -p a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
@@ -1782,7 +1782,7 @@ static int adt7462_detect(struct i2c_cli
 	if (revision != ADT7462_REVISION)
 		return -ENODEV;
 
-	strlcpy(info->type, "adt7462", I2C_NAME_SIZE);
+	stracpy(info->type, "adt7462");
 
 	return 0;
 }
drivers/hwmon/w83795.c +1 -1
diff -u -p a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
@@ -1967,7 +1967,7 @@ static int w83795_detect(struct i2c_clie
 	else
 		chip_name = "w83795g";
 
-	strlcpy(info->type, chip_name, I2C_NAME_SIZE);
+	stracpy(info->type, chip_name);
 	dev_info(&adapter->dev, "Found %s rev. %c at 0x%02hx\n", chip_name,
 		 'A' + (device_id & 0xf), address);
 
drivers/s390/char/hmcdrv_cache.c +1 -2
diff -u -p a/drivers/s390/char/hmcdrv_cache.c b/drivers/s390/char/hmcdrv_cache.c
@@ -154,8 +154,7 @@ static ssize_t hmcdrv_cache_do(const str
 		/* cache some file info (FTP command, file name and file
 		 * size) unconditionally
 		 */
-		strlcpy(hmcdrv_cache_file.fname, ftp->fname,
-			HMCDRV_FTP_FIDENT_MAX);
+		stracpy(hmcdrv_cache_file.fname, ftp->fname);
 		hmcdrv_cache_file.id = ftp->id;
 		pr_debug("caching cmd %d, file size %zu for '%s'\n",
 			 ftp->id, hmcdrv_cache_file.fsize, ftp->fname);
drivers/soc/qcom/apr.c +1 -1
diff -u -p a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
@@ -273,7 +273,7 @@ static int apr_add_device(struct device
 	if (np)
 		snprintf(adev->name, APR_NAME_SIZE, "%pOFn", np);
 	else
-		strscpy(adev->name, id->name, APR_NAME_SIZE);
+		stracpy(adev->name, id->name);
 
 	dev_set_name(&adev->dev, "aprsvc:%s:%x:%x", adev->name,
 		     id->domain_id, id->svc_id);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -4
diff -u -p a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3346,9 +3346,8 @@ static void fill_audio_info(struct audio
 
 	cea_revision = drm_connector->display_info.cea_rev;
 
-	strscpy(audio_info->display_name,
-		edid_caps->display_name,
-		AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS);
+	stracpy(audio_info->display_name,
+		edid_caps->display_name);
 
 	if (cea_revision >= 3) {
 		audio_info->mode_count = edid_caps->audio_mode_count;
@@ -4850,7 +4849,7 @@ amdgpu_dm_create_common_mode(struct drm_
 	mode->hdisplay = hdisplay;
 	mode->vdisplay = vdisplay;
 	mode->type &= ~DRM_MODE_TYPE_PREFERRED;
-	strscpy(mode->name, name, DRM_DISPLAY_MODE_LEN);
+	stracpy(mode->name, name);
 
 	return mode;
 
drivers/media/usb/cx231xx/cx231xx-input.c +1 -1
diff -u -p a/drivers/media/usb/cx231xx/cx231xx-input.c b/drivers/media/usb/cx231xx/cx231xx-input.c
@@ -67,7 +67,7 @@ int cx231xx_ir_init(struct cx231xx *dev)
 
 	dev->init_data.name = cx231xx_boards[dev->model].name;
 
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 	info.platform_data = &dev->init_data;
 
 	/*
drivers/target/target_core_configfs.c +1 -1
diff -u -p a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
@@ -618,7 +618,7 @@ static void dev_set_t10_wwn_model_alias(
 	 * here without potentially breaking existing setups, so continue to
 	 * truncate one byte shorter than what can be carried in INQUIRY.
 	 */
-	strlcpy(dev->t10_wwn.model, configname, INQUIRY_MODEL_LEN);
+	stracpy(dev->t10_wwn.model, configname);
 }
 
 static ssize_t emulate_model_alias_store(struct config_item *item,
drivers/hwmon/lm95245.c +1 -1
diff -u -p a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c
@@ -461,7 +461,7 @@ static int lm95245_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	return 0;
 }
 
drivers/scsi/bfa/bfa_fcs_lport.c +5 -5
diff -u -p a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -2655,13 +2655,13 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_
 	bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
 	hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
 
-	strlcpy(hba_attr->node_sym_name.symname,
-		port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
+	stracpy(hba_attr->node_sym_name.symname,
+		port->port_cfg.node_sym_name.symname);
 	strcpy(hba_attr->vendor_info, "QLogic");
 	hba_attr->num_ports =
 		cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
 	hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
-	strlcpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
+	stracpy(hba_attr->bios_ver, hba_attr->option_rom_ver);
 
 }
 
@@ -2740,8 +2740,8 @@ bfa_fcs_fdmi_get_portattr(struct bfa_fcs
 	port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
 	port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
 
-	strlcpy(port_attr->port_sym_name.symname,
-		bfa_fcs_lport_get_psym_name(port).symname, BFA_SYMNAME_MAXLEN);
+	stracpy(port_attr->port_sym_name.symname,
+		bfa_fcs_lport_get_psym_name(port).symname);
 	bfa_fcs_lport_get_attr(port, &lport_attr);
 	port_attr->port_type = cpu_to_be32(lport_attr.port_type);
 	port_attr->scos = pport_attr.cos_supported;
net/bridge/br_sysfs_if.c +2 -2
diff -u -p a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
@@ -374,7 +374,7 @@ int br_sysfs_addif(struct net_bridge_por
 			return err;
 	}
 
-	strlcpy(p->sysfs_name, p->dev->name, IFNAMSIZ);
+	stracpy(p->sysfs_name, p->dev->name);
 	return sysfs_create_link(br->ifobj, &p->kobj, p->sysfs_name);
 }
 
@@ -396,7 +396,7 @@ int br_sysfs_renameif(struct net_bridge_
 		netdev_notice(br->dev, "unable to rename link %s to %s",
 			      p->sysfs_name, p->dev->name);
 	else
-		strlcpy(p->sysfs_name, p->dev->name, IFNAMSIZ);
+		stracpy(p->sysfs_name, p->dev->name);
 
 	return err;
 }
drivers/hwmon/max1668.c +1 -1
diff -u -p a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c
@@ -386,7 +386,7 @@ static int max1668_detect(struct i2c_cli
 	if (!type_name)
 		return -ENODEV;
 
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
drivers/misc/ics932s401.c +1 -1
diff -u -p a/drivers/misc/ics932s401.c b/drivers/misc/ics932s401.c
@@ -424,7 +424,7 @@ static int ics932s401_detect(struct i2c_
 	if (revision != ICS932S401_REV)
 		dev_info(&adapter->dev, "Unknown revision %d\n", revision);
 
-	strlcpy(info->type, "ics932s401", I2C_NAME_SIZE);
+	stracpy(info->type, "ics932s401");
 
 	return 0;
 }
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +1 -2
diff -u -p a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -3364,8 +3364,7 @@ static void bnx2x_drv_info_ether_stat(st
 		&bp->sp_objs->mac_obj;
 	int i;
 
-	strlcpy(ether_stat->version, DRV_MODULE_VERSION,
-		ETH_STAT_INFO_VERSION_LEN);
+	stracpy(ether_stat->version, DRV_MODULE_VERSION);
 
 	/* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
 	 * mac_local field in ether_stat struct. The base address is offset by 2
drivers/hwmon/lm95234.c +1 -1
diff -u -p a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
@@ -644,7 +644,7 @@ static int lm95234_detect(struct i2c_cli
 	if (val & model_mask)
 		return -ENODEV;
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	return 0;
 }
 
drivers/i2c/busses/i2c-i801.c +3 -3
diff -u -p a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
@@ -1134,7 +1134,7 @@ static void dmi_check_onboard_device(u8
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		info.addr = dmi_devices[i].i2c_addr;
-		strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
+		stracpy(info.type, dmi_devices[i].i2c_type);
 		i2c_new_device(adap, &info);
 		break;
 	}
@@ -1279,7 +1279,7 @@ static void register_dell_lis3lv02d_i2c_
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.addr = dell_lis3lv02d_devices[i].i2c_addr;
-	strlcpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
+	stracpy(info.type, "lis3lv02d");
 	i2c_new_device(&priv->adapter, &info);
 }
 
@@ -1295,7 +1295,7 @@ static void i801_probe_optional_slaves(s
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		info.addr = apanel_addr;
-		strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
+		stracpy(info.type, "fujitsu_apanel");
 		i2c_new_device(&priv->adapter, &info);
 	}
 
drivers/media/usb/dvb-usb/cxusb.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
@@ -1406,7 +1406,7 @@ static int cxusb_mygica_t230_frontend_at
 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
 	si2168_config.ts_clock_inv = 1;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "si2168", I2C_NAME_SIZE);
+	stracpy(info.type, "si2168");
 	info.addr = 0x64;
 	info.platform_data = &si2168_config;
 	request_module(info.type);
@@ -1426,7 +1426,7 @@ static int cxusb_mygica_t230_frontend_at
 	si2157_config.fe = adap->fe_adap[0].fe;
 	si2157_config.if_port = 1;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "si2157", I2C_NAME_SIZE);
+	stracpy(info.type, "si2157");
 	info.addr = 0x60;
 	info.platform_data = &si2157_config;
 	request_module(info.type);
drivers/hwmon/adm1026.c +1 -1
diff -u -p a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
@@ -1610,7 +1610,7 @@ static int adm1026_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "adm1026", I2C_NAME_SIZE);
+	stracpy(info->type, "adm1026");
 
 	return 0;
 }
drivers/hwmon/stts751.c +1 -1
diff -u -p a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
@@ -692,7 +692,7 @@ static int stts751_detect(struct i2c_cli
 	}
 	dev_dbg(&new_client->dev, "Chip %s detected", name);
 
-	strlcpy(info->type, stts751_id[0].name, I2C_NAME_SIZE);
+	stracpy(info->type, stts751_id[0].name);
 	return 0;
 }
 
drivers/media/pci/smipcie/smipcie-main.c +4 -4
diff -u -p a/drivers/media/pci/smipcie/smipcie-main.c b/drivers/media/pci/smipcie/smipcie-main.c
@@ -540,7 +540,7 @@ static int smi_dvbsky_m88ds3103_fe_attac
 	}
 	/* attach tuner */
 	ts2020_config.fe = port->fe;
-	strscpy(tuner_info.type, "ts2020", I2C_NAME_SIZE);
+	stracpy(tuner_info.type, "ts2020");
 	tuner_info.addr = 0x60;
 	tuner_info.platform_data = &ts2020_config;
 	tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info);
@@ -596,7 +596,7 @@ static int smi_dvbsky_m88rs6000_fe_attac
 	}
 	/* attach tuner */
 	m88rs6000t_config.fe = port->fe;
-	strscpy(tuner_info.type, "m88rs6000t", I2C_NAME_SIZE);
+	stracpy(tuner_info.type, "m88rs6000t");
 	tuner_info.addr = 0x21;
 	tuner_info.platform_data = &m88rs6000t_config;
 	tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info);
@@ -638,7 +638,7 @@ static int smi_dvbsky_sit2_fe_attach(str
 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
 
 	memset(&client_info, 0, sizeof(struct i2c_board_info));
-	strscpy(client_info.type, "si2168", I2C_NAME_SIZE);
+	stracpy(client_info.type, "si2168");
 	client_info.addr = 0x64;
 	client_info.platform_data = &si2168_config;
 
@@ -655,7 +655,7 @@ static int smi_dvbsky_sit2_fe_attach(str
 	si2157_config.if_port = 1;
 
 	memset(&client_info, 0, sizeof(struct i2c_board_info));
-	strscpy(client_info.type, "si2157", I2C_NAME_SIZE);
+	stracpy(client_info.type, "si2157");
 	client_info.addr = 0x60;
 	client_info.platform_data = &si2157_config;
 
drivers/hwmon/lm77.c +1 -1
diff -u -p a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
@@ -302,7 +302,7 @@ static int lm77_detect(struct i2c_client
 	 || i2c_smbus_read_word_data(client, 7) != min)
 		return -ENODEV;
 
-	strlcpy(info->type, "lm77", I2C_NAME_SIZE);
+	stracpy(info->type, "lm77");
 
 	return 0;
 }
drivers/media/pci/saa7164/saa7164-dvb.c +5 -5
diff -u -p a/drivers/media/pci/saa7164/saa7164-dvb.c b/drivers/media/pci/saa7164/saa7164-dvb.c
@@ -110,7 +110,7 @@ static int si2157_attach(struct saa7164_
 
 	memset(&bi, 0, sizeof(bi));
 
-	strscpy(bi.type, "si2157", I2C_NAME_SIZE);
+	stracpy(bi.type, "si2157");
 	bi.platform_data = cfg;
 	bi.addr = addr8bit >> 1;
 
@@ -633,7 +633,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2168_config.fe = &port->dvb.frontend;
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0xc8 >> 1;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -653,7 +653,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2157_config.if_port = 1;
 			si2157_config.fe = port->dvb.frontend;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0xc0 >> 1;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
@@ -678,7 +678,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2168_config.fe = &port->dvb.frontend;
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0xcc >> 1;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -698,7 +698,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2157_config.fe = port->dvb.frontend;
 			si2157_config.if_port = 1;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0xc0 >> 1;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
lib/earlycpio.c +1 -1
diff -u -p a/lib/earlycpio.c b/lib/earlycpio.c
@@ -126,7 +126,7 @@ struct cpio_data find_cpio_data(const ch
 				"File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
 				p, MAX_CPIO_FILE_NAME);
 			}
-			strlcpy(cd.name, p + mypathsize, MAX_CPIO_FILE_NAME);
+			stracpy(cd.name, p + mypathsize);
 
 			cd.data = (void *)dptr;
 			cd.size = ch[C_FILESIZE];
crypto/api.c +1 -1
diff -u -p a/crypto/api.c b/crypto/api.c
@@ -115,7 +115,7 @@ struct crypto_larval *crypto_larval_allo
 	larval->alg.cra_priority = -1;
 	larval->alg.cra_destroy = crypto_larval_destroy;
 
-	strlcpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME);
+	stracpy(larval->alg.cra_name, name);
 	init_completion(&larval->completion);
 
 	return larval;
drivers/hwmon/lm87.c +1 -1
diff -u -p a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
@@ -833,7 +833,7 @@ static int lm87_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/misc/eeprom/eeprom.c +1 -1
diff -u -p a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
@@ -136,7 +136,7 @@ static int eeprom_detect(struct i2c_clie
 	 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
 		return -ENODEV;
 
-	strlcpy(info->type, "eeprom", I2C_NAME_SIZE);
+	stracpy(info->type, "eeprom");
 
 	return 0;
 }
drivers/net/ethernet/hp/hp100.c +1 -1
diff -u -p a/drivers/net/ethernet/hp/hp100.c b/drivers/net/ethernet/hp/hp100.c
@@ -643,7 +643,7 @@ static int hp100_probe1(struct net_devic
 	lp = netdev_priv(dev);
 
 	spin_lock_init(&lp->lock);
-	strlcpy(lp->id, eid, HP100_SIG_LEN);
+	stracpy(lp->id, eid);
 	lp->chip = chip;
 	lp->mode = local_mode;
 	lp->bus = bus;
drivers/s390/block/dasd_devmap.c +1 -1
diff -u -p a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
@@ -426,7 +426,7 @@ dasd_add_busid(const char *bus_id, int f
 	if (!devmap) {
 		/* This bus_id is new. */
 		new->devindex = dasd_max_devindex++;
-		strlcpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
+		stracpy(new->bus_id, bus_id);
 		new->features = features;
 		new->device = NULL;
 		list_add(&new->list, &dasd_hashlists[hash]);
sound/aoa/codecs/onyx.c +1 -1
diff -u -p a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
@@ -1011,7 +1011,7 @@ static int onyx_i2c_probe(struct i2c_cli
 		goto fail;
 	}
 
-	strlcpy(onyx->codec.name, "onyx", MAX_CODEC_NAME_LEN);
+	stracpy(onyx->codec.name, "onyx");
 	onyx->codec.owner = THIS_MODULE;
 	onyx->codec.init = onyx_init_codec;
 	onyx->codec.exit = onyx_exit_codec;
drivers/hwmon/ftsteutates.c +1 -1
diff -u -p a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c
@@ -739,7 +739,7 @@ static int fts_detect(struct i2c_client
 	if (val != 0x11)
 		return -ENODEV;
 
-	strlcpy(info->type, fts_id[0].name, I2C_NAME_SIZE);
+	stracpy(info->type, fts_id[0].name);
 	info->flags = 0;
 	return 0;
 }
net/mac80211/iface.c +1 -1
diff -u -p a/net/mac80211/iface.c b/net/mac80211/iface.c
@@ -1745,7 +1745,7 @@ int ieee80211_if_add(struct ieee80211_lo
 		wdev = &sdata->wdev;
 
 		sdata->dev = NULL;
-		strlcpy(sdata->name, name, IFNAMSIZ);
+		stracpy(sdata->name, name);
 		ieee80211_assign_perm_addr(local, wdev->address, type);
 		memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
 	} else {
drivers/crypto/chelsio/chtls/chtls_main.c +1 -1
diff -u -p a/drivers/crypto/chelsio/chtls/chtls_main.c b/drivers/crypto/chelsio/chtls/chtls_main.c
@@ -185,7 +185,7 @@ static void chtls_register_dev(struct ch
 {
 	struct tls_device *tlsdev = &cdev->tlsdev;
 
-	strlcpy(tlsdev->name, "chtls", TLS_DEVICE_NAME_MAX);
+	stracpy(tlsdev->name, "chtls");
 	strlcat(tlsdev->name, cdev->lldi->ports[0]->name,
 		TLS_DEVICE_NAME_MAX);
 	tlsdev->feature = chtls_inline_feature;
drivers/media/pci/saa7134/saa7134-input.c +1 -1
diff -u -p a/drivers/media/pci/saa7134/saa7134-input.c b/drivers/media/pci/saa7134/saa7134-input.c
@@ -856,7 +856,7 @@ void saa7134_probe_i2c_ir(struct saa7134
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	memset(&dev->init_data, 0, sizeof(dev->init_data));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (dev->board) {
 	case SAA7134_BOARD_PINNACLE_PCTV_110i:
drivers/hwmon/lm85.c +1 -1
diff -u -p a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
@@ -1539,7 +1539,7 @@ static int lm85_detect(struct i2c_client
 	if (!type_name)
 		return -ENODEV;
 
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
drivers/media/dvb-frontends/cxd2820r_core.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -527,7 +527,7 @@ struct dvb_frontend *cxd2820r_attach(con
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "cxd2820r", I2C_NAME_SIZE);
+	stracpy(board_info.type, "cxd2820r");
 	board_info.addr = config->i2c_address;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(adapter, &board_info);
drivers/media/pci/cx23885/cx23885-dvb.c +27 -27

216 lines not on this page · raw message

drivers/media/usb/dvb-usb-v2/rtl28xxu.c +9 -9
diff -u -p a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -693,7 +693,7 @@ static int rtl2831u_frontend_attach(stru
 
 	/* attach demodulator */
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
+	stracpy(board_info.type, "rtl2830");
 	board_info.addr = 0x10;
 	board_info.platform_data = pdata;
 	request_module("%s", board_info.type);
@@ -914,7 +914,7 @@ static int rtl2832u_frontend_attach(stru
 
 	/* attach demodulator */
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
+	stracpy(board_info.type, "rtl2832");
 	board_info.addr = 0x10;
 	board_info.platform_data = pdata;
 	request_module("%s", board_info.type);
@@ -953,7 +953,7 @@ static int rtl2832u_frontend_attach(stru
 
 			mn88472_config.fe = &adap->fe[1];
 			mn88472_config.i2c_wr_max = 22,
-			strscpy(info.type, "mn88472", I2C_NAME_SIZE);
+			stracpy(info.type, "mn88472");
 			mn88472_config.xtal = 20500000;
 			mn88472_config.ts_mode = SERIAL_TS_MODE;
 			mn88472_config.ts_clock = VARIABLE_TS_CLOCK;
@@ -978,7 +978,7 @@ static int rtl2832u_frontend_attach(stru
 
 			mn88473_config.fe = &adap->fe[1];
 			mn88473_config.i2c_wr_max = 22,
-			strscpy(info.type, "mn88473", I2C_NAME_SIZE);
+			stracpy(info.type, "mn88473");
 			info.addr = 0x18;
 			info.platform_data = &mn88473_config;
 			request_module(info.type);
@@ -1021,7 +1021,7 @@ static int rtl2832u_frontend_attach(stru
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			si2168_config.ts_clock_inv = false;
 			si2168_config.ts_clock_gapped = true;
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0x64;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -1212,7 +1212,7 @@ static int rtl2832u_tuner_attach(struct
 				.clock = 28800000,
 			};
 
-			strscpy(info.type, "e4000", I2C_NAME_SIZE);
+			stracpy(info.type, "e4000");
 			info.addr = 0x64;
 			info.platform_data = &e4000_config;
 
@@ -1236,7 +1236,7 @@ static int rtl2832u_tuner_attach(struct
 			};
 			struct i2c_board_info board_info = {};
 
-			strscpy(board_info.type, "fc2580", I2C_NAME_SIZE);
+			stracpy(board_info.type, "fc2580");
 			board_info.addr = 0x56;
 			board_info.platform_data = &fc2580_pdata;
 			request_module("fc2580");
@@ -1267,7 +1267,7 @@ static int rtl2832u_tuner_attach(struct
 		if (ret)
 			goto err;
 
-		strscpy(board_info.type, "tua9001", I2C_NAME_SIZE);
+		stracpy(board_info.type, "tua9001");
 		board_info.addr = 0x60;
 		board_info.platform_data = &tua9001_pdata;
 		request_module("tua9001");
@@ -1312,7 +1312,7 @@ static int rtl2832u_tuner_attach(struct
 				.inversion = false,
 			};
 
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0x60;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
drivers/firmware/arm_scmi/perf.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
@@ -174,7 +174,7 @@ scmi_perf_domain_attributes_get(const st
 			dom_info->mult_factor =
 					(dom_info->sustained_freq_khz * 1000) /
 					dom_info->sustained_perf_level;
-		strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
+		stracpy(dom_info->name, attr->name);
 	}
 
 	scmi_xfer_put(handle, t);
drivers/hwmon/f75375s.c +1 -1
diff -u -p a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
@@ -899,7 +899,7 @@ static int f75375_detect(struct i2c_clie
 
 	version = f75375_read8(client, F75375_REG_VERSION);
 	dev_info(&adapter->dev, "found %s version: %02X\n", name, version);
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/adm9240.c +1 -1
diff -u -p a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
@@ -657,7 +657,7 @@ static int adm9240_detect(struct i2c_cli
 		 man_id == 0x23 ? "ADM9240" :
 		 man_id == 0xda ? "DS1780" : "LM81", die_rev);
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/smsc47m192.c +1 -1
diff -u -p a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
@@ -582,7 +582,7 @@ static int smsc47m192_detect(struct i2c_
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE);
+	stracpy(info->type, "smsc47m192");
 
 	return 0;
 }
drivers/media/pci/ivtv/ivtv-i2c.c +2 -2
diff -u -p a/drivers/media/pci/ivtv/ivtv-i2c.c b/drivers/media/pci/ivtv/ivtv-i2c.c
@@ -206,7 +206,7 @@ static int ivtv_i2c_new_ir(struct ivtv *
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.platform_data = init_data;
-	strscpy(info.type, type, I2C_NAME_SIZE);
+	stracpy(info.type, type);
 
 	return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
 	       -1 : 0;
@@ -234,7 +234,7 @@ struct i2c_client *ivtv_i2c_new_ir_legac
 	};
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 	return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL);
 }
 
drivers/hwmon/lm63.c +3 -3
diff -u -p a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
@@ -996,11 +996,11 @@ static int lm63_detect(struct i2c_client
 	}
 
 	if (chip_id == 0x41 && address == 0x4c)
-		strlcpy(info->type, "lm63", I2C_NAME_SIZE);
+		stracpy(info->type, "lm63");
 	else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e))
-		strlcpy(info->type, "lm64", I2C_NAME_SIZE);
+		stracpy(info->type, "lm64");
 	else if (chip_id == 0x49 && address == 0x4c)
-		strlcpy(info->type, "lm96163", I2C_NAME_SIZE);
+		stracpy(info->type, "lm96163");
 	else
 		return -ENODEV;
 
drivers/infiniband/core/device.c +2 -2
diff -u -p a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
@@ -429,7 +429,7 @@ int ib_device_rename(struct ib_device *i
 		return ret;
 	}
 
-	strlcpy(ibdev->name, name, IB_DEVICE_NAME_MAX);
+	stracpy(ibdev->name, name);
 	ret = rename_compat_devs(ibdev);
 
 	downgrade_write(&devices_rwsem);
@@ -1142,7 +1142,7 @@ static int assign_name(struct ib_device
 		ret = -ENFILE;
 		goto out;
 	}
-	strlcpy(device->name, dev_name(&device->dev), IB_DEVICE_NAME_MAX);
+	stracpy(device->name, dev_name(&device->dev));
 
 	ret = xa_alloc_cyclic(&devices, &device->index, device, xa_limit_31b,
 			&last_id, GFP_KERNEL);
drivers/media/usb/tm6000/tm6000-i2c.c +1 -1
diff -u -p a/drivers/media/usb/tm6000/tm6000-i2c.c b/drivers/media/usb/tm6000/tm6000-i2c.c
@@ -300,7 +300,7 @@ int tm6000_i2c_register(struct tm6000_co
 		return rc;
 
 	dev->i2c_client.adapter = &dev->i2c_adap;
-	strscpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE);
+	stracpy(dev->i2c_client.name, "tm6000 internal");
 	tm6000_i2c_eeprom(dev);
 
 	return 0;
drivers/hwmon/lm73.c +1 -1
diff -u -p a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
@@ -257,7 +257,7 @@ static int lm73_detect(struct i2c_client
 	if (id < 0 || id != LM73_ID)
 		return -ENODEV;
 
-	strlcpy(info->type, "lm73", I2C_NAME_SIZE);
+	stracpy(info->type, "lm73");
 
 	return 0;
 }
drivers/media/dvb-frontends/m88ds3103.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c
@@ -1274,7 +1274,7 @@ struct dvb_frontend *m88ds3103_attach(co
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
+	stracpy(board_info.type, "m88ds3103");
 	board_info.addr = cfg->i2c_addr;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(i2c, &board_info);
drivers/net/ethernet/realtek/r8169_firmware.c +2 -2
diff -u -p a/drivers/net/ethernet/realtek/r8169_firmware.c b/drivers/net/ethernet/realtek/r8169_firmware.c
@@ -68,7 +68,7 @@ static bool rtl_fw_format_ok(struct rtl_
 		if (size > (fw->size - start) / FW_OPCODE_SIZE)
 			return false;
 
-		strscpy(rtl_fw->version, fw_info->version, RTL_VER_SIZE);
+		stracpy(rtl_fw->version, fw_info->version);
 
 		pa->code = (__le32 *)(fw->data + start);
 		pa->size = size;
@@ -76,7 +76,7 @@ static bool rtl_fw_format_ok(struct rtl_
 		if (fw->size % FW_OPCODE_SIZE)
 			return false;
 
-		strscpy(rtl_fw->version, rtl_fw->fw_name, RTL_VER_SIZE);
+		stracpy(rtl_fw->version, rtl_fw->fw_name);
 
 		pa->code = (__le32 *)fw->data;
 		pa->size = fw->size / FW_OPCODE_SIZE;
drivers/platform/x86/i2c-multi-instantiate.c +1 -1
diff -u -p a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c
@@ -91,7 +91,7 @@ static int i2c_multi_inst_probe(struct p
 
 	for (i = 0; i < multi->num_clients && inst_data[i].type; i++) {
 		memset(&board_info, 0, sizeof(board_info));
-		strlcpy(board_info.type, inst_data[i].type, I2C_NAME_SIZE);
+		stracpy(board_info.type, inst_data[i].type);
 		snprintf(name, sizeof(name), "%s-%s.%d", match->id,
 			 inst_data[i].type, i);
 		board_info.dev_name = name;
drivers/staging/comedi/comedi_fops.c +2 -2
diff -u -p a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
@@ -937,8 +937,8 @@ static int do_devinfo_ioctl(struct comed
 	/* fill devinfo structure */
 	devinfo.version_code = COMEDI_VERSION_CODE;
 	devinfo.n_subdevs = dev->n_subdevices;
-	strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN);
-	strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN);
+	stracpy(devinfo.driver_name, dev->driver->driver_name);
+	stracpy(devinfo.board_name, dev->board_name);
 
 	s = comedi_file_read_subdevice(file);
 	if (s)
drivers/usb/wusbcore/cbaf.c +2 -2
diff -u -p a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
@@ -241,7 +241,7 @@ static int cbaf_send_host_info(struct cb
 	*hi = cbaf_host_info_defaults;
 	hi->CHID = cbaf->chid;
 	hi->LangID = 0;	/* FIXME: I guess... */
-	strlcpy(hi->HostFriendlyName, cbaf->host_name, CBA_NAME_LEN);
+	stracpy(hi->HostFriendlyName, cbaf->host_name);
 	name_len = strlen(cbaf->host_name);
 	hi->HostFriendlyName_hdr.len = cpu_to_le16(name_len);
 	hi_size = sizeof(*hi) + name_len;
@@ -289,7 +289,7 @@ static int cbaf_cdid_get(struct cbaf *cb
 		return -ENOENT;
 	}
 
-	strlcpy(cbaf->device_name, di->DeviceFriendlyName, CBA_NAME_LEN);
+	stracpy(cbaf->device_name, di->DeviceFriendlyName);
 	cbaf->cdid = di->CDID;
 	cbaf->device_band_groups = le16_to_cpu(di->BandGroups);
 
drivers/hwmon/lm83.c +1 -1
diff -u -p a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
@@ -312,7 +312,7 @@ static int lm83_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/media/i2c/saa7127.c +2 -2
diff -u -p a/drivers/media/i2c/saa7127.c b/drivers/media/i2c/saa7127.c
@@ -752,10 +752,10 @@ static int saa7127_probe(struct i2c_clie
 			saa7127_write(sd, SAA7129_REG_FADE_KEY_COL2,
 					read_result);
 			state->ident = SAA7129;
-			strscpy(client->name, "saa7129", I2C_NAME_SIZE);
+			stracpy(client->name, "saa7129");
 		} else {
 			state->ident = SAA7127;
-			strscpy(client->name, "saa7127", I2C_NAME_SIZE);
+			stracpy(client->name, "saa7127");
 		}
 	}
 
drivers/target/target_core_user.c +2 -2
diff -u -p a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
@@ -2344,14 +2344,14 @@ static ssize_t tcmu_dev_config_store(str
 			pr_err("Unable to reconfigure device\n");
 			return ret;
 		}
-		strlcpy(udev->dev_config, page, TCMU_CONFIG_LEN);
+		stracpy(udev->dev_config, page);
 
 		ret = tcmu_update_uio_info(udev);
 		if (ret)
 			return ret;
 		return count;
 	}
-	strlcpy(udev->dev_config, page, TCMU_CONFIG_LEN);
+	stracpy(udev->dev_config, page);
 
 	return count;
 }
drivers/char/ipmi/ipmi_ssif.c +1 -1
diff -u -p a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
@@ -1397,7 +1397,7 @@ static int ssif_detect(struct i2c_client
 	if (rv)
 		rv = -ENODEV;
 	else
-		strlcpy(info->type, DEVICE_NAME, I2C_NAME_SIZE);
+		stracpy(info->type, DEVICE_NAME);
 	kfree(resp);
 	return rv;
 }
drivers/hwmon/jc42.c +1 -1
diff -u -p a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
@@ -431,7 +431,7 @@ static int jc42_detect(struct i2c_client
 		struct jc42_chips *chip = &jc42_chips[i];
 		if (manid == chip->manid &&
 		    (devid & chip->devid_mask) == chip->devid) {
-			strlcpy(info->type, "jc42", I2C_NAME_SIZE);
+			stracpy(info->type, "jc42");
 			return 0;
 		}
 	}
drivers/media/usb/dvb-usb-v2/anysee.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/anysee.c b/drivers/media/usb/dvb-usb-v2/anysee.c
@@ -629,7 +629,7 @@ static int anysee_add_i2c_dev(struct dvb
 		.platform_data = platform_data,
 	};
 
-	strscpy(board_info.type, type, I2C_NAME_SIZE);
+	stracpy(board_info.type, type);
 
 	/* find first free client */
 	for (num = 0; num < ANYSEE_I2C_CLIENT_MAX; num++) {
kernel/cgroup/cgroup.c +2 -2
diff -u -p a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
@@ -1980,9 +1980,9 @@ void init_cgroup_root(struct cgroup_fs_c
 
 	root->flags = ctx->flags;
 	if (ctx->release_agent)
-		strscpy(root->release_agent_path, ctx->release_agent, PATH_MAX);
+		stracpy(root->release_agent_path, ctx->release_agent);
 	if (ctx->name)
-		strscpy(root->name, ctx->name, MAX_CGROUP_ROOT_NAMELEN);
+		stracpy(root->name, ctx->name);
 	if (ctx->cpuset_clone_children)
 		set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags);
 }
drivers/hwmon/lm75.c +1 -1
diff -u -p a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
@@ -607,7 +607,7 @@ static int lm75_detect(struct i2c_client
 			return -ENODEV;
 	}
 
-	strlcpy(info->type, is_lm75a ? "lm75a" : "lm75", I2C_NAME_SIZE);
+	stracpy(info->type, is_lm75a ? "lm75a" : "lm75");
 
 	return 0;
 }
drivers/net/macvlan.c +1 -1
diff -u -p a/drivers/net/macvlan.c b/drivers/net/macvlan.c
@@ -827,7 +827,7 @@ static int macvlan_do_ioctl(struct net_d
 	struct ifreq ifrr;
 	int err = -EOPNOTSUPP;
 
-	strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
+	stracpy(ifrr.ifr_name, real_dev->name);
 	ifrr.ifr_ifru = ifr->ifr_ifru;
 
 	switch (cmd) {
drivers/thermal/thermal_hwmon.c +1 -1
diff -u -p a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
@@ -141,7 +141,7 @@ int thermal_add_hwmon_sysfs(struct therm
 		return -ENOMEM;
 
 	INIT_LIST_HEAD(&hwmon->tz_list);
-	strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
+	stracpy(hwmon->type, tz->type);
 	strreplace(hwmon->type, '-', '_');
 	hwmon->device = hwmon_device_register_with_info(&tz->device, hwmon->type,
 							hwmon, NULL, NULL);
arch/powerpc/platforms/powernv/idle.c +1 -2
diff -u -p a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
@@ -1311,8 +1311,7 @@ static int pnv_parse_cpuidle_dt(void)
 		goto out;
 	}
 	for (i = 0; i < nr_idle_states; i++)
-		strlcpy(pnv_idle_states[i].name, temp_string[i],
-			PNV_IDLE_NAME_LEN);
+		stracpy(pnv_idle_states[i].name, temp_string[i]);
 	nr_pnv_idle_states = nr_idle_states;
 	rc = 0;
 out:
drivers/hwmon/adm1021.c +1 -1
diff -u -p a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
@@ -411,7 +411,7 @@ static int adm1021_detect(struct i2c_cli
 
 	pr_debug("Detected chip %s at adapter %d, address 0x%02x.\n",
 		 type_name, i2c_adapter_id(adapter), client->addr);
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
drivers/hwmon/thmc50.c +1 -1
diff -u -p a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c
@@ -352,7 +352,7 @@ static int thmc50_detect(struct i2c_clie
 	pr_debug("thmc50: Detected %s (version %x, revision %x)\n",
 		 type_name, (revision >> 4) - 0xc, revision & 0xf);
 
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
drivers/s390/cio/qdio_debug.c +1 -1
diff -u -p a/drivers/s390/cio/qdio_debug.c b/drivers/s390/cio/qdio_debug.c
@@ -101,7 +101,7 @@ int qdio_allocate_dbf(struct qdio_initia
 			debug_unregister(irq_ptr->debug_area);
 			return -ENOMEM;
 		}
-		strlcpy(new_entry->dbf_name, text, QDIO_DBF_NAME_LEN);
+		stracpy(new_entry->dbf_name, text);
 		new_entry->dbf_info = irq_ptr->debug_area;
 		mutex_lock(&qdio_dbf_list_mutex);
 		list_add(&new_entry->dbf_list, &qdio_dbf_list);
drivers/staging/greybus/audio_module.c +1 -1
diff -u -p a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c
@@ -341,7 +341,7 @@ static int gb_audio_probe(struct gb_bund
 	/* inform above layer for uevent */
 	dev_dbg(dev, "Inform set_event:%d to above layer\n", 1);
 	/* prepare for the audio manager */
-	strlcpy(desc.name, gbmodule->name, GB_AUDIO_MANAGER_MODULE_NAME_LEN);
+	stracpy(desc.name, gbmodule->name);
 	desc.vid = 2; /* todo */
 	desc.pid = 3; /* todo */
 	desc.intf_id = gbmodule->dev_id;
drivers/hwmon/dme1737.c +1 -1
diff -u -p a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
@@ -2456,7 +2456,7 @@ static int dme1737_i2c_detect(struct i2c
 	dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
 		 verstep == SCH5027_VERSTEP ? "SCH5027" : "DME1737",
 		 client->addr, verstep);
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
sound/ppc/keywest.c +1 -1
diff -u -p a/sound/ppc/keywest.c b/sound/ppc/keywest.c
@@ -48,7 +48,7 @@ static int keywest_attach_adapter(struct
 		return -EINVAL; /* ignored */
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strlcpy(info.type, "keywest", I2C_NAME_SIZE);
+	stracpy(info.type, "keywest");
 	info.addr = keywest_ctx->addr;
 	keywest_ctx->client = i2c_new_device(adapter, &info);
 	if (!keywest_ctx->client)
drivers/hwmon/emc6w201.c +1 -1
diff -u -p a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
@@ -439,7 +439,7 @@ static int emc6w201_detect(struct i2c_cl
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "emc6w201", I2C_NAME_SIZE);
+	stracpy(info->type, "emc6w201");
 
 	return 0;
 }
drivers/hwmon/w83l786ng.c +1 -1
diff -u -p a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
@@ -687,7 +687,7 @@ w83l786ng_detect(struct i2c_client *clie
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE);
+	stracpy(info->type, "w83l786ng");
 
 	return 0;
 }
drivers/media/pci/cx88/cx88-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx88/cx88-i2c.c b/drivers/media/pci/cx88/cx88-i2c.c
@@ -137,7 +137,7 @@ int cx88_i2c_init(struct cx88_core *core
 	i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev);
 	core->i2c_adap.algo_data = &core->i2c_algo;
 	core->i2c_client.adapter = &core->i2c_adap;
-	strscpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE);
+	stracpy(core->i2c_client.name, "cx88xx internal");
 
 	cx8800_bit_setscl(core, 1);
 	cx8800_bit_setsda(core, 1);
net/netfilter/ipset/ip_set_core.c +1 -1
diff -u -p a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
@@ -917,7 +917,7 @@ static int ip_set_create(struct net *net
 	if (!set)
 		return -ENOMEM;
 	spin_lock_init(&set->lock);
-	strlcpy(set->name, name, IPSET_MAXNAMELEN);
+	stracpy(set->name, name);
 	set->family = family;
 	set->revision = revision;
 
drivers/hwmon/adt7470.c +1 -1
diff -u -p a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
@@ -1200,7 +1200,7 @@ static int adt7470_detect(struct i2c_cli
 	if (revision != ADT7470_REVISION)
 		return -ENODEV;
 
-	strlcpy(info->type, "adt7470", I2C_NAME_SIZE);
+	stracpy(info->type, "adt7470");
 
 	return 0;
 }
drivers/hwmon/w83792d.c +1 -1
diff -u -p a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
@@ -1361,7 +1361,7 @@ w83792d_detect(struct i2c_client *client
 	if (val1 != 0x7a || val2 != 0x5c)
 		return -ENODEV;
 
-	strlcpy(info->type, "w83792d", I2C_NAME_SIZE);
+	stracpy(info->type, "w83792d");
 
 	return 0;
 }
net/l2tp/l2tp_eth.c +1 -1
diff -u -p a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
@@ -328,7 +328,7 @@ static int l2tp_eth_create(struct net *n
 		return rc;
 	}
 
-	strlcpy(session->ifname, dev->name, IFNAMSIZ);
+	stracpy(session->ifname, dev->name);
 	rcu_assign_pointer(spriv->dev, dev);
 
 	rtnl_unlock();
drivers/firmware/arm_scmi/clock.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
@@ -111,7 +111,7 @@ static int scmi_clock_attributes_get(con
 
 	ret = scmi_do_xfer(handle, t);
 	if (!ret)
-		strlcpy(clk->name, attr->name, SCMI_MAX_STR_SIZE);
+		stracpy(clk->name, attr->name);
 	else
 		clk->name[0] = '\0';
 
drivers/hwmon/lm78.c +1 -1
diff -u -p a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
@@ -617,7 +617,7 @@ static int lm78_i2c_detect(struct i2c_cl
 	if (isa)
 		mutex_unlock(&isa->update_lock);
 
-	strlcpy(info->type, client_name, I2C_NAME_SIZE);
+	stracpy(info->type, client_name);
 
 	return 0;
 
drivers/media/pci/cx23885/cx23885-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx23885/cx23885-i2c.c b/drivers/media/pci/cx23885/cx23885-i2c.c
@@ -334,7 +334,7 @@ int cx23885_i2c_register(struct cx23885_
 		};
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
-		strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_video");
 		/* Use quick read command for probe, some IR chips don't
 		 * support writes */
 		i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
drivers/tty/serial/earlycon.c +1 -1
diff -u -p a/drivers/tty/serial/earlycon.c b/drivers/tty/serial/earlycon.c
@@ -118,7 +118,7 @@ static int __init parse_options(struct e
 		device->baud = simple_strtoul(options, NULL, 0);
 		length = min(strcspn(options, " ") + 1,
 			     (size_t)(sizeof(device->options)));
-		strlcpy(device->options, options, length);
+		stracpy(device->options, options);
 	}
 
 	return 0;
net/ipv4/ip_tunnel.c +1 -1
diff -u -p a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
@@ -1054,7 +1054,7 @@ int ip_tunnel_init_net(struct net *net,
 
 	memset(&parms, 0, sizeof(parms));
 	if (devname)
-		strlcpy(parms.name, devname, IFNAMSIZ);
+		stracpy(parms.name, devname);
 
 	rtnl_lock();
 	itn->fb_tunnel_dev = __ip_tunnel_create(net, ops, &parms);
drivers/clk/tegra/clk-bpmp.c +1 -1
diff -u -p a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
@@ -344,7 +344,7 @@ static int tegra_bpmp_clk_get_info(struc
 	if (err < 0)
 		return err;
 
-	strlcpy(info->name, response.name, MRQ_CLK_NAME_MAXLEN);
+	stracpy(info->name, response.name);
 	info->num_parents = response.num_parents;
 
 	for (i = 0; i < info->num_parents; i++)
drivers/hwmon/emc1403.c +6 -6
diff -u -p a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
@@ -329,22 +329,22 @@ static int emc1403_detect(struct i2c_cli
 	id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG);
 	switch (id) {
 	case 0x20:
-		strlcpy(info->type, "emc1402", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1402");
 		break;
 	case 0x21:
-		strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1403");
 		break;
 	case 0x22:
-		strlcpy(info->type, "emc1422", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1422");
 		break;
 	case 0x23:
-		strlcpy(info->type, "emc1423", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1423");
 		break;
 	case 0x25:
-		strlcpy(info->type, "emc1404", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1404");
 		break;
 	case 0x27:
-		strlcpy(info->type, "emc1424", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1424");
 		break;
 	default:
 		return -ENODEV;
drivers/hwmon/tmp401.c +1 -1
diff -u -p a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
@@ -678,7 +678,7 @@ static int tmp401_detect(struct i2c_clie
 	if (reg > 15)
 		return -ENODEV;
 
-	strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE);
+	stracpy(info->type, tmp401_id[kind].name);
 
 	return 0;
 }
fs/orangefs/orangefs-utils.c +2 -3
diff -u -p a/fs/orangefs/orangefs-utils.c b/fs/orangefs/orangefs-utils.c
@@ -335,9 +335,8 @@ again2:
 		if (flags & ORANGEFS_GETATTR_NEW) {
 			inode->i_size = (loff_t)strlen(new_op->
 			    downcall.resp.getattr.link_target);
-			ret = strscpy(orangefs_inode->link_target,
-			    new_op->downcall.resp.getattr.link_target,
-			    ORANGEFS_NAME_MAX);
+			ret = stracpy(orangefs_inode->link_target,
+			    new_op->downcall.resp.getattr.link_target);
 			if (ret == -E2BIG) {
 				ret = -EIO;
 				goto out_unlock;
drivers/cpuidle/cpuidle-powernv.c +2 -2
diff -u -p a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
@@ -236,8 +236,8 @@ static inline void add_powernv_state(int
 				     unsigned int exit_latency,
 				     u64 psscr_val, u64 psscr_mask)
 {
-	strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);
-	strlcpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN);
+	stracpy(powernv_states[index].name, name);
+	stracpy(powernv_states[index].desc, name);
 	powernv_states[index].flags = flags;
 	powernv_states[index].target_residency = target_residency;
 	powernv_states[index].exit_latency = exit_latency;
drivers/hwmon/amc6821.c +1 -1
diff -u -p a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
@@ -809,7 +809,7 @@ static int amc6821_detect(
 	}
 
 	dev_info(&adapter->dev, "amc6821: chip found at 0x%02x.\n", address);
-	strlcpy(info->type, "amc6821", I2C_NAME_SIZE);
+	stracpy(info->type, "amc6821");
 
 	return 0;
 }
drivers/hwmon/nct7802.c +1 -1
diff -u -p a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
@@ -959,7 +959,7 @@ static int nct7802_detect(struct i2c_cli
 	if (reg < 0 || (reg & 0x3f))
 		return -ENODEV;
 
-	strlcpy(info->type, "nct7802", I2C_NAME_SIZE);
+	stracpy(info->type, "nct7802");
 	return 0;
 }
 
drivers/media/pci/cx18/cx18-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx18/cx18-i2c.c b/drivers/media/pci/cx18/cx18-i2c.c
@@ -74,7 +74,7 @@ static int cx18_i2c_new_ir(struct cx18 *
 	unsigned short addr_list[2] = { addr, I2C_CLIENT_END };
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, type, I2C_NAME_SIZE);
+	stracpy(info.type, type);
 
 	/* Our default information for ir-kbd-i2c.c to use */
 	switch (hw) {
drivers/media/usb/dvb-usb/dib0700_devices.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/dib0700_devices.c b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -3760,7 +3760,7 @@ static int xbox_one_attach(struct dvb_us
 	mn88472_config.ts_mode = PARALLEL_TS_MODE;
 	mn88472_config.ts_clock = FIXED_TS_CLOCK;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "mn88472", I2C_NAME_SIZE);
+	stracpy(info.type, "mn88472");
 	info.addr = 0x18;
 	info.platform_data = &mn88472_config;
 	request_module(info.type);
@@ -3787,7 +3787,7 @@ static int xbox_one_attach(struct dvb_us
 	tda18250_config.fe = adap->fe_adap[0].fe;
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "tda18250", I2C_NAME_SIZE);
+	stracpy(info.type, "tda18250");
 	info.addr = 0x60;
 	info.platform_data = &tda18250_config;
 
drivers/scsi/bfa/bfad_bsg.c +2 -2
diff -u -p a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
@@ -119,8 +119,8 @@ bfad_iocmd_ioc_get_attr(struct bfad_s *b
 
 	/* fill in driver attr info */
 	strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME);
-	strlcpy(iocmd->ioc_attr.driver_attr.driver_ver,
-		BFAD_DRIVER_VERSION, BFA_VERSION_LEN);
+	stracpy(iocmd->ioc_attr.driver_attr.driver_ver,
+		BFAD_DRIVER_VERSION);
 	strcpy(iocmd->ioc_attr.driver_attr.fw_ver,
 		iocmd->ioc_attr.adapter_attr.fw_ver);
 	strcpy(iocmd->ioc_attr.driver_attr.bios_ver,
drivers/hwmon/asc7621.c +1 -2
diff -u -p a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c
@@ -1153,8 +1153,7 @@ static int asc7621_detect(struct i2c_cli
 
 		if (company == asc7621_chips[chip_index].company_id &&
 		    verstep == asc7621_chips[chip_index].verstep_id) {
-			strlcpy(info->type, asc7621_chips[chip_index].name,
-				I2C_NAME_SIZE);
+			stracpy(info->type, asc7621_chips[chip_index].name);
 
 			dev_info(&adapter->dev, "Matched %s at 0x%02x\n",
 				 asc7621_chips[chip_index].name, client->addr);
drivers/hwmon/nct7904.c +1 -1
diff -u -p a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
@@ -397,7 +397,7 @@ static int nct7904_detect(struct i2c_cli
 	    (i2c_smbus_read_byte_data(client, BANK_SEL_REG) & 0xf8) != 0x00)
 		return -ENODEV;
 
-	strlcpy(info->type, "nct7904", I2C_NAME_SIZE);
+	stracpy(info->type, "nct7904");
 
 	return 0;
 }
kernel/kallsyms.c +1 -1
diff -u -p a/kernel/kallsyms.c b/kernel/kallsyms.c
@@ -495,7 +495,7 @@ static int get_ksymbol_ftrace_mod(struct
 
 static int get_ksymbol_bpf(struct kallsym_iter *iter)
 {
-	strlcpy(iter->module_name, "bpf", MODULE_NAME_LEN);
+	stracpy(iter->module_name, "bpf");
 	iter->exported = 0;
 	return bpf_get_kallsym(iter->pos - iter->pos_ftrace_mod_end,
 			       &iter->value, &iter->type,
tools/perf/arch/x86/util/machine.c +1 -1
diff -u -p a/tools/perf/arch/x86/util/machine.c b/tools/perf/arch/x86/util/machine.c
@@ -39,7 +39,7 @@ static int add_extra_kernel_map(struct e
 	mi->maps[mi->cnt].start = start;
 	mi->maps[mi->cnt].end   = end;
 	mi->maps[mi->cnt].pgoff = pgoff;
-	strlcpy(mi->maps[mi->cnt].name, name, KMAP_NAME_LEN);
+	stracpy(mi->maps[mi->cnt].name, name);
 
 	mi->cnt += 1;
 
drivers/hwmon/max1619.c +1 -1
diff -u -p a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
@@ -241,7 +241,7 @@ static int max1619_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "max1619", I2C_NAME_SIZE);
+	stracpy(info->type, "max1619");
 
 	return 0;
 }
drivers/media/dvb-core/dvb_vb2.c +1 -1
diff -u -p a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c
@@ -193,7 +193,7 @@ int dvb_vb2_init(struct dvb_vb2_ctx *ctx
 	spin_lock_init(&ctx->slock);
 	INIT_LIST_HEAD(&ctx->dvb_q);
 
-	strscpy(ctx->name, name, DVB_VB2_NAME_MAX);
+	stracpy(ctx->name, name);
 	ctx->nonblocking = nonblocking;
 	ctx->state = DVB_VB2_STATE_INIT;
 
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +2 -2
diff -u -p a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c
@@ -2367,8 +2367,8 @@ static void rvu_update_module_params(str
 {
 	const char *default_pfl_name = "default";
 
-	strscpy(rvu->mkex_pfl_name,
-		mkex_profile ? mkex_profile : default_pfl_name, MKEX_NAME_LEN);
+	stracpy(rvu->mkex_pfl_name,
+		mkex_profile ? mkex_profile : default_pfl_name);
 }
 
 static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
drivers/hwmon/lm95241.c +1 -1
diff -u -p a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
@@ -389,7 +389,7 @@ static int lm95241_detect(struct i2c_cli
 	}
 
 	/* Fill the i2c board info */
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	return 0;
 }
 
drivers/media/usb/dvb-usb-v2/zd1301.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/zd1301.c b/drivers/media/usb/dvb-usb-v2/zd1301.c
@@ -168,7 +168,7 @@ static int zd1301_frontend_attach(struct
 	dev->mt2060_pdata.i2c_write_max = 9;
 	dev->mt2060_pdata.dvb_frontend = frontend;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "mt2060", I2C_NAME_SIZE);
+	stracpy(board_info.type, "mt2060");
 	board_info.addr = 0x60;
 	board_info.platform_data = &dev->mt2060_pdata;
 	request_module("%s", "mt2060");
drivers/nvme/host/fabrics.c +1 -1
diff -u -p a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
@@ -49,7 +49,7 @@ static struct nvmf_host *nvmf_host_add(c
 		goto out_unlock;
 
 	kref_init(&host->ref);
-	strlcpy(host->nqn, hostnqn, NVMF_NQN_SIZE);
+	stracpy(host->nqn, hostnqn);
 
 	list_add_tail(&host->list, &nvmf_hosts);
 out_unlock:
drivers/hwmon/lm92.c +1 -1
diff -u -p a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
@@ -287,7 +287,7 @@ static int lm92_detect(struct i2c_client
 	else
 		return -ENODEV;
 
-	strlcpy(info->type, "lm92", I2C_NAME_SIZE);
+	stracpy(info->type, "lm92");
 
 	return 0;
 }
drivers/net/ethernet/qlogic/qede/qede_main.c +1 -1
diff -u -p a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c
@@ -1094,7 +1094,7 @@ static int __qede_probe(struct pci_dev *
 	sp_params.drv_minor = QEDE_MINOR_VERSION;
 	sp_params.drv_rev = QEDE_REVISION_VERSION;
 	sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
-	strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
+	stracpy(sp_params.name, "qede LAN");
 	rc = qed_ops->common->slowpath_start(cdev, &sp_params);
 	if (rc) {
 		pr_notice("Cannot start slowpath\n");
drivers/scsi/bfa/bfa_fcs.c +2 -4
diff -u -p a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
@@ -761,8 +761,7 @@ bfa_fcs_fabric_psymb_init(struct bfa_fcs
 	bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
 
 	/* Model name/number */
-	strlcpy(port_cfg->sym_name.symname, model,
-		BFA_SYMNAME_MAXLEN);
+	stracpy(port_cfg->sym_name.symname, model);
 	strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
 		BFA_SYMNAME_MAXLEN);
 
@@ -822,8 +821,7 @@ bfa_fcs_fabric_nsymb_init(struct bfa_fcs
 	bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
 
 	/* Model name/number */
-	strlcpy(port_cfg->node_sym_name.symname, model,
-		BFA_SYMNAME_MAXLEN);
+	stracpy(port_cfg->node_sym_name.symname, model);
 	strlcat(port_cfg->node_sym_name.symname,
 			BFA_FCS_PORT_SYMBNAME_SEPARATOR,
 			BFA_SYMNAME_MAXLEN);
net/core/dev.c +3 -3
diff -u -p a/net/core/dev.c b/net/core/dev.c
@@ -572,7 +572,7 @@ static int netdev_boot_setup_add(char *n
 	for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
 		if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
 			memset(s[i].name, 0, sizeof(s[i].name));
-			strlcpy(s[i].name, name, IFNAMSIZ);
+			stracpy(s[i].name, name);
 			memcpy(&s[i].map, map, sizeof(s[i].map));
 			break;
 		}
@@ -1117,7 +1117,7 @@ static int dev_alloc_name_ns(struct net
 	BUG_ON(!net);
 	ret = __dev_alloc_name(net, name, buf);
 	if (ret >= 0)
-		strlcpy(dev->name, buf, IFNAMSIZ);
+		stracpy(dev->name, buf);
 	return ret;
 }
 
@@ -1154,7 +1154,7 @@ int dev_get_valid_name(struct net *net,
 	else if (__dev_get_by_name(net, name))
 		return -EEXIST;
 	else if (dev->name != name)
-		strlcpy(dev->name, name, IFNAMSIZ);
+		stracpy(dev->name, name);
 
 	return 0;
 }
drivers/hwmon/gl520sm.c +1 -1
diff -u -p a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
@@ -811,7 +811,7 @@ static int gl520_detect(struct i2c_clien
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "gl520sm", I2C_NAME_SIZE);
+	stracpy(info->type, "gl520sm");
 
 	return 0;
 }
drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c +1 -2
diff -u -p a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
@@ -733,8 +733,7 @@ brcmf_fw_alloc_request(u32 chip, u32 chi
 		fwnames[j].path[0] = '\0';
 		/* check if firmware path is provided by module parameter */
 		if (brcmf_mp_global.firmware_path[0] != '\0') {
-			strlcpy(fwnames[j].path, mp_path,
-				BRCMF_FW_NAME_LEN);
+			stracpy(fwnames[j].path, mp_path);
 
 			if (end != '/') {
 				strlcat(fwnames[j].path, "/",
drivers/usb/usbip/stub_main.c +1 -1
diff -u -p a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
@@ -101,7 +101,7 @@ static int add_match_busid(char *busid)
 	for (i = 0; i < MAX_BUSID; i++) {
 		spin_lock(&busid_table[i].busid_lock);
 		if (!busid_table[i].name[0]) {
-			strlcpy(busid_table[i].name, busid, BUSID_SIZE);
+			stracpy(busid_table[i].name, busid);
 			if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
 			    (busid_table[i].status != STUB_BUSID_REMOV))
 				busid_table[i].status = STUB_BUSID_ADDED;
drivers/hwmon/lm80.c +1 -1
diff -u -p a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
@@ -586,7 +586,7 @@ static int lm80_detect(struct i2c_client
 		name = "lm80";
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/media/dvb-frontends/ts2020.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
@@ -516,7 +516,7 @@ struct dvb_frontend *ts2020_attach(struc
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "ts2020", I2C_NAME_SIZE);
+	stracpy(board_info.type, "ts2020");
 	board_info.addr = config->tuner_address;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(i2c, &board_info);
kernel/workqueue.c +1 -1
diff -u -p a/kernel/workqueue.c b/kernel/workqueue.c
@@ -2208,7 +2208,7 @@ __acquires(&pool->lock)
 	 * Record wq name for cmdline and debug reporting, may get
 	 * overridden through set_worker_desc().
 	 */
-	strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN);
+	stracpy(worker->desc, pwq->wq->name);
 
 	list_del_init(&work->entry);
 
net/sched/sch_teql.c +1 -1
diff -u -p a/net/sched/sch_teql.c b/net/sched/sch_teql.c
@@ -489,7 +489,7 @@ static int __init teql_init(void)
 
 		master = netdev_priv(dev);
 
-		strlcpy(master->qops.id, dev->name, IFNAMSIZ);
+		stracpy(master->qops.id, dev->name);
 		err = register_qdisc(&master->qops);
 
 		if (err) {
drivers/firmware/arm_scmi/power.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/power.c b/drivers/firmware/arm_scmi/power.c
@@ -106,7 +106,7 @@ scmi_power_domain_attributes_get(const s
 		dom_info->state_set_notify = SUPPORTS_STATE_SET_NOTIFY(flags);
 		dom_info->state_set_async = SUPPORTS_STATE_SET_ASYNC(flags);
 		dom_info->state_set_sync = SUPPORTS_STATE_SET_SYNC(flags);
-		strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
+		stracpy(dom_info->name, attr->name);
 	}
 
 	scmi_xfer_put(handle, t);
drivers/hwmon/adm1025.c +1 -1
diff -u -p a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
@@ -470,7 +470,7 @@ static int adm1025_detect(struct i2c_cli
 	else
 		return -ENODEV;
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/w83791d.c +1 -1
diff -u -p a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
@@ -1349,7 +1349,7 @@ static int w83791d_detect(struct i2c_cli
 	if (val1 != 0x71 || val2 != 0x5c)
 		return -ENODEV;
 
-	strlcpy(info->type, "w83791d", I2C_NAME_SIZE);
+	stracpy(info->type, "w83791d");
 
 	return 0;
 }
drivers/media/pci/bt8xx/bttv-input.c +1 -1
diff -u -p a/drivers/media/pci/bt8xx/bttv-input.c b/drivers/media/pci/bt8xx/bttv-input.c
@@ -373,7 +373,7 @@ void init_bttv_i2c_ir(struct bttv *btv)
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	memset(&btv->init_data, 0, sizeof(btv->init_data));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (btv->c.type) {
 	case BTTV_BOARD_PV951:
drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c +2 -2
diff -u -p a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
@@ -561,7 +561,7 @@ static void pvr2_i2c_register_ir(struct
 		/* IR Receiver */
 		info.addr          = 0x18;
 		info.platform_data = init_data;
-		strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_video");
 		pvr2_trace(PVR2_TRACE_INFO, "Binding %s to i2c address 0x%02x.",
 			   info.type, info.addr);
 		i2c_new_device(&hdw->i2c_adap, &info);
@@ -576,7 +576,7 @@ static void pvr2_i2c_register_ir(struct
 		/* IR Transceiver */
 		info.addr = 0x71;
 		info.platform_data = init_data;
-		strscpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_z8f0811_haup");
 		pvr2_trace(PVR2_TRACE_INFO, "Binding %s to i2c address 0x%02x.",
 			   info.type, info.addr);
 		i2c_new_device(&hdw->i2c_adap, &info);
drivers/platform/x86/intel_cht_int33fe.c +3 -3
diff -u -p a/drivers/platform/x86/intel_cht_int33fe.c b/drivers/platform/x86/intel_cht_int33fe.c
@@ -285,7 +285,7 @@ cht_int33fe_register_max17047(struct dev
 	}
 
 	memset(&board_info, 0, sizeof(board_info));
-	strlcpy(board_info.type, "max17047", I2C_NAME_SIZE);
+	stracpy(board_info.type, "max17047");
 	board_info.dev_name = "max17047";
 	board_info.fwnode = fwnode;
 	data->max17047 = i2c_acpi_new_device(dev, 1, &board_info);
@@ -374,7 +374,7 @@ static int cht_int33fe_probe(struct plat
 	}
 
 	memset(&board_info, 0, sizeof(board_info));
-	strlcpy(board_info.type, "typec_fusb302", I2C_NAME_SIZE);
+	stracpy(board_info.type, "typec_fusb302");
 	board_info.dev_name = "fusb302";
 	board_info.fwnode = fwnode;
 	board_info.irq = fusb302_irq;
@@ -394,7 +394,7 @@ static int cht_int33fe_probe(struct plat
 	memset(&board_info, 0, sizeof(board_info));
 	board_info.dev_name = "pi3usb30532";
 	board_info.fwnode = fwnode;
-	strlcpy(board_info.type, "pi3usb30532", I2C_NAME_SIZE);
+	stracpy(board_info.type, "pi3usb30532");
 
 	data->pi3usb30532 = i2c_acpi_new_device(dev, 3, &board_info);
 	if (IS_ERR(data->pi3usb30532)) {
drivers/hwmon/gl518sm.c +1 -1
diff -u -p a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
@@ -586,7 +586,7 @@ static int gl518_detect(struct i2c_clien
 	if (rev != 0x00 && rev != 0x80)
 		return -ENODEV;
 
-	strlcpy(info->type, "gl518sm", I2C_NAME_SIZE);
+	stracpy(info->type, "gl518sm");
 
 	return 0;
 }
fs/gfs2/ops_fstype.c +5 -5
diff -u -p a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
@@ -372,8 +372,8 @@ static int init_names(struct gfs2_sbd *s
 	if (!table[0])
 		table = sdp->sd_vfs->s_id;
 
-	strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
-	strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
+	stracpy(sdp->sd_proto_name, proto);
+	stracpy(sdp->sd_table_name, table);
 
 	table = sdp->sd_table_name;
 	while ((table = strchr(table, '/')))
@@ -1346,13 +1346,13 @@ static int gfs2_parse_param(struct fs_co
 
 	switch (o) {
 	case Opt_lockproto:
-		strlcpy(args->ar_lockproto, param->string, GFS2_LOCKNAME_LEN);
+		stracpy(args->ar_lockproto, param->string);
 		break;
 	case Opt_locktable:
-		strlcpy(args->ar_locktable, param->string, GFS2_LOCKNAME_LEN);
+		stracpy(args->ar_locktable, param->string);
 		break;
 	case Opt_hostdata:
-		strlcpy(args->ar_hostdata, param->string, GFS2_LOCKNAME_LEN);
+		stracpy(args->ar_hostdata, param->string);
 		break;
 	case Opt_spectator:
 		args->ar_spectator = 1;
sound/aoa/codecs/tas.c +1 -1
diff -u -p a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
@@ -894,7 +894,7 @@ static int tas_i2c_probe(struct i2c_clie
 	/* seems that half is a saner default */
 	tas->drc_range = TAS3004_DRC_MAX / 2;
 
-	strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN);
+	stracpy(tas->codec.name, "tas");
 	tas->codec.owner = THIS_MODULE;
 	tas->codec.init = tas_init_codec;
 	tas->codec.exit = tas_exit_codec;
drivers/hwmon/asb100.c +1 -1
diff -u -p a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
@@ -770,7 +770,7 @@ static int asb100_detect(struct i2c_clie
 	if (val1 != 0x31 || val2 != 0x06)
 		return -ENODEV;
 
-	strlcpy(info->type, "asb100", I2C_NAME_SIZE);
+	stracpy(info->type, "asb100");
 
 	return 0;
 }
drivers/hwmon/tmp421.c +1 -1
diff -u -p a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
@@ -266,7 +266,7 @@ static int tmp421_detect(struct i2c_clie
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, tmp421_id[kind].name, I2C_NAME_SIZE);
+	stracpy(info->type, tmp421_id[kind].name);
 	dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n",
 		 names[kind], client->addr);
 
drivers/media/pci/bt8xx/bttv-i2c.c +1 -1
diff -u -p a/drivers/media/pci/bt8xx/bttv-i2c.c b/drivers/media/pci/bt8xx/bttv-i2c.c
@@ -335,7 +335,7 @@ static void do_i2c_scan(char *name, stru
 /* init + register i2c adapter */
 int init_bttv_i2c(struct bttv *btv)
 {
-	strscpy(btv->i2c_client.name, "bttv internal", I2C_NAME_SIZE);
+	stracpy(btv->i2c_client.name, "bttv internal");
 
 	if (i2c_hw)
 		btv->use_i2c_hw = 1;
drivers/hwmon/adm1029.c +1 -1
diff -u -p a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c
@@ -329,7 +329,7 @@ static int adm1029_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "adm1029", I2C_NAME_SIZE);
+	stracpy(info->type, "adm1029");
 
 	return 0;
 }
drivers/hwmon/w83793.c +1 -1
diff -u -p a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
@@ -1651,7 +1651,7 @@ static int w83793_detect(struct i2c_clie
 	if (chip_id != 0x7b)
 		return -ENODEV;
 
-	strlcpy(info->type, "w83793", I2C_NAME_SIZE);
+	stracpy(info->type, "w83793");
 
 	return 0;
 }
drivers/media/usb/dvb-usb-v2/af9035.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -189,7 +189,7 @@ static int af9035_add_i2c_dev(struct dvb
 		.platform_data = platform_data,
 	};
 
-	strscpy(board_info.type, type, I2C_NAME_SIZE);
+	stracpy(board_info.type, type);
 
 	/* find first free client */
 	for (num = 0; num < AF9035_I2C_CLIENT_MAX; num++) {
drivers/gpu/drm/drm_client.c +1 -1
diff -u -p a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
@@ -347,7 +347,7 @@ static int drm_client_buffer_addfb(struc
 	/* drop the reference we picked up in framebuffer lookup */
 	drm_framebuffer_put(buffer->fb);
 
-	strscpy(buffer->fb->comm, client->name, TASK_COMM_LEN);
+	stracpy(buffer->fb->comm, client->name);
 
 	return 0;
 }
drivers/hwmon/max6639.c +1 -1
diff -u -p a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
@@ -511,7 +511,7 @@ static int max6639_detect(struct i2c_cli
 	if (dev_id != 0x58 || manu_id != 0x4D)
 		return -ENODEV;
 
-	strlcpy(info->type, "max6639", I2C_NAME_SIZE);
+	stracpy(info->type, "max6639");
 
 	return 0;
 }
drivers/acpi/processor_idle.c +4 -5
diff -u -p a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
@@ -865,7 +865,7 @@ static int acpi_processor_setup_cstates(
 
 		state = &drv->states[count];
 		snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
-		strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
+		stracpy(state->desc, cx->desc);
 		state->exit_latency = cx->latency;
 		state->target_residency = cx->latency * latency_factor;
 		state->enter = acpi_idle_enter;
@@ -1036,8 +1036,7 @@ static int acpi_processor_evaluate_lpi(a
 
 		obj = pkg_elem + 9;
 		if (obj->type == ACPI_TYPE_STRING)
-			strlcpy(lpi_state->desc, obj->string.pointer,
-				ACPI_CX_DESC_LEN);
+			stracpy(lpi_state->desc, obj->string.pointer);
 
 		lpi_state->index = state_idx;
 		if (obj_get_integer(pkg_elem + 0, &lpi_state->min_residency)) {
@@ -1102,7 +1101,7 @@ static bool combine_lpi_states(struct ac
 	result->arch_flags = parent->arch_flags;
 	result->index = parent->index;
 
-	strlcpy(result->desc, local->desc, ACPI_CX_DESC_LEN);
+	stracpy(result->desc, local->desc);
 	strlcat(result->desc, "+", ACPI_CX_DESC_LEN);
 	strlcat(result->desc, parent->desc, ACPI_CX_DESC_LEN);
 	return true;
@@ -1271,7 +1270,7 @@ static int acpi_processor_setup_lpi_stat
 
 		state = &drv->states[i];
 		snprintf(state->name, CPUIDLE_NAME_LEN, "LPI-%d", i);
-		strlcpy(state->desc, lpi->desc, CPUIDLE_DESC_LEN);
+		stracpy(state->desc, lpi->desc);
 		state->exit_latency = lpi->wake_latency;
 		state->target_residency = lpi->min_residency;
 		if (lpi->arch_flags)
drivers/hwmon/fschmd.c +1 -1
diff -u -p a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
@@ -1075,7 +1075,7 @@ static int fschmd_detect(struct i2c_clie
 	else
 		return -ENODEV;
 
-	strlcpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE);
+	stracpy(info->type, fschmd_id[kind].name);
 
 	return 0;
 }
drivers/leds/leds-blinkm.c +1 -1
diff -u -p a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c
@@ -562,7 +562,7 @@ static int blinkm_detect(struct i2c_clie
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "blinkm", I2C_NAME_SIZE);
+	stracpy(info->type, "blinkm");
 	return 0;
 }
 
drivers/hwmon/emc2103.c +1 -1
diff -u -p a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c
@@ -643,7 +643,7 @@ emc2103_detect(struct i2c_client *new_cl
 	if ((product != 0x24) && (product != 0x26))
 		return -ENODEV;
 
-	strlcpy(info->type, "emc2103", I2C_NAME_SIZE);
+	stracpy(info->type, "emc2103");
 
 	return 0;
 }
drivers/s390/char/tape_class.c +2 -2
diff -u -p a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
@@ -54,10 +54,10 @@ struct tape_class_device *register_tape_
 	if (!tcd)
 		return ERR_PTR(-ENOMEM);
 
-	strlcpy(tcd->device_name, device_name, TAPECLASS_NAME_LEN);
+	stracpy(tcd->device_name, device_name);
 	for (s = strchr(tcd->device_name, '/'); s; s = strchr(s, '/'))
 		*s = '!';
-	strlcpy(tcd->mode_name, mode_name, TAPECLASS_NAME_LEN);
+	stracpy(tcd->mode_name, mode_name);
 	for (s = strchr(tcd->mode_name, '/'); s; s = strchr(s, '/'))
 		*s = '!';
 
fs/ocfs2/super.c +1 -2
diff -u -p a/fs/ocfs2/super.c b/fs/ocfs2/super.c
@@ -2239,8 +2239,7 @@ static int ocfs2_initialize_super(struct
 		goto bail;
 	}
 
-	strlcpy(osb->vol_label, di->id2.i_super.s_label,
-		OCFS2_MAX_VOL_LABEL_LEN);
+	stracpy(osb->vol_label, di->id2.i_super.s_label);
 	osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
 	osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
 	osb->first_cluster_group_blkno =
drivers/hwmon/lm93.c +1 -1
diff -u -p a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c
@@ -2575,7 +2575,7 @@ static int lm93_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	dev_dbg(&adapter->dev, "loading %s at %d, 0x%02x\n",
 		client->name, i2c_adapter_id(client->adapter),
 		client->addr);
drivers/media/pci/cx88/cx88-input.c +2 -2
diff -u -p a/drivers/media/pci/cx88/cx88-input.c b/drivers/media/pci/cx88/cx88-input.c
@@ -600,7 +600,7 @@ void cx88_i2c_init_ir(struct cx88_core *
 		return;
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (core->boardnr) {
 	case CX88_BOARD_LEADTEK_PVR2000:
@@ -625,7 +625,7 @@ void cx88_i2c_init_ir(struct cx88_core *
 
 		if (*addrp == 0x71) {
 			/* Hauppauge Z8F0811 */
-			strscpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE);
+			stracpy(info.type, "ir_z8f0811_haup");
 			core->init_data.name = core->board.name;
 			core->init_data.ir_codes = RC_MAP_HAUPPAUGE;
 			core->init_data.type = RC_PROTO_BIT_RC5 |
drivers/mfd/htc-i2cpld.c +1 -1
diff -u -p a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c
@@ -351,7 +351,7 @@ static int htcpld_register_chip_i2c(
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.addr = plat_chip_data->addr;
-	strlcpy(info.type, "htcpld-chip", I2C_NAME_SIZE);
+	stracpy(info.type, "htcpld-chip");
 	info.platform_data = chip;
 
 	/* Add the I2C device.  This calls the probe() function. */
drivers/nvme/host/core.c +1 -1
diff -u -p a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
@@ -2292,7 +2292,7 @@ static void nvme_init_subnqn(struct nvme
 	if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) {
 		nqnlen = strnlen(id->subnqn, NVMF_NQN_SIZE);
 		if (nqnlen > 0 && nqnlen < NVMF_NQN_SIZE) {
-			strlcpy(subsys->subnqn, id->subnqn, NVMF_NQN_SIZE);
+			stracpy(subsys->subnqn, id->subnqn);
 			return;
 		}
 
drivers/hwmon/adc128d818.c +1 -1
diff -u -p a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c
@@ -384,7 +384,7 @@ static int adc128_detect(struct i2c_clie
 	if (i2c_smbus_read_byte_data(client, ADC128_REG_BUSY_STATUS) & 0xfc)
 		return -ENODEV;
 
-	strlcpy(info->type, "adc128d818", I2C_NAME_SIZE);
+	stracpy(info->type, "adc128d818");
 
 	return 0;
 }
drivers/hwmon/max6642.c +1 -1
diff -u -p a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c
@@ -148,7 +148,7 @@ static int max6642_detect(struct i2c_cli
 	if ((reg_status & 0x2b) != 0x00)
 		return -ENODEV;
 
-	strlcpy(info->type, "max6642", I2C_NAME_SIZE);
+	stracpy(info->type, "max6642");
 
 	return 0;
 }
drivers/media/i2c/tvaudio.c +1 -1
diff -u -p a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
@@ -1981,7 +1981,7 @@ static int tvaudio_probe(struct i2c_clie
 
 	/* fill required data structures */
 	if (!id)
-		strscpy(client->name, desc->name, I2C_NAME_SIZE);
+		stracpy(client->name, desc->name);
 	chip->desc = desc;
 	chip->shadow.count = desc->registers+1;
 	chip->prevmode = -1;
drivers/media/usb/dvb-usb/dw2102.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
@@ -1586,7 +1586,7 @@ static int tt_s2_4600_frontend_attach(st
 	m88ds3103_pdata.lnb_hv_pol = 1;
 	m88ds3103_pdata.lnb_en_pol = 0;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
+	stracpy(board_info.type, "m88ds3103");
 	board_info.addr = 0x68;
 	board_info.platform_data = &m88ds3103_pdata;
 	request_module("m88ds3103");
@@ -1605,7 +1605,7 @@ static int tt_s2_4600_frontend_attach(st
 	/* attach tuner */
 	ts2020_config.fe = adap->fe_adap[0].fe;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "ts2022", I2C_NAME_SIZE);
+	stracpy(board_info.type, "ts2022");
 	board_info.addr = 0x60;
 	board_info.platform_data = &ts2020_config;
 	request_module("ts2020");
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +3 -5
diff -u -p a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
@@ -383,13 +383,11 @@ static void brcmf_mp_attach(void)
 	 * if not set then if available use the platform data version. To make
 	 * sure it gets initialized at all, always copy the module param version
 	 */
-	strlcpy(brcmf_mp_global.firmware_path, brcmf_firmware_path,
-		BRCMF_FW_ALTPATH_LEN);
+	stracpy(brcmf_mp_global.firmware_path, brcmf_firmware_path);
 	if ((brcmfmac_pdata) && (brcmfmac_pdata->fw_alternative_path) &&
 	    (brcmf_mp_global.firmware_path[0] == '\0')) {
-		strlcpy(brcmf_mp_global.firmware_path,
-			brcmfmac_pdata->fw_alternative_path,
-			BRCMF_FW_ALTPATH_LEN);
+		stracpy(brcmf_mp_global.firmware_path,
+			brcmfmac_pdata->fw_alternative_path);
 	}
 }
 
tools/perf/util/auxtrace.c +1 -1
diff -u -p a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
@@ -865,7 +865,7 @@ void auxtrace_synth_error(struct auxtrac
 	auxtrace_error->fmt = 1;
 	auxtrace_error->ip = ip;
 	auxtrace_error->time = timestamp;
-	strlcpy(auxtrace_error->msg, msg, MAX_AUXTRACE_ERROR_MSG);
+	stracpy(auxtrace_error->msg, msg);
 
 	size = (void *)auxtrace_error->msg - (void *)auxtrace_error +
 	       strlen(auxtrace_error->msg) + 1;
drivers/hwmon/adt7411.c +1 -1
diff -u -p a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
@@ -590,7 +590,7 @@ static int adt7411_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "adt7411", I2C_NAME_SIZE);
+	stracpy(info->type, "adt7411");
 
 	return 0;
 }
drivers/macintosh/therm_windtunnel.c +2 -2
diff -u -p a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
@@ -320,10 +320,10 @@ do_attach( struct i2c_adapter *adapter )
 		struct i2c_board_info info;
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
-		strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE);
+		stracpy(info.type, "therm_ds1775");
 		i2c_new_probed_device(adapter, &info, scan_ds1775, NULL);
 
-		strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE);
+		stracpy(info.type, "therm_adm1030");
 		i2c_new_probed_device(adapter, &info, scan_adm1030, NULL);
 
 		if( x.thermostat && x.fan ) {
drivers/media/v4l2-core/v4l2-ioctl.c +1 -1
diff -u -p a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1371,7 +1371,7 @@ static void v4l_fill_fmtdesc(struct v4l2
 	}
 
 	if (descr)
-		WARN_ON(strscpy(fmt->description, descr, sz) < 0);
+		WARN_ON(stracpy(fmt->description, descr) < 0);
 	fmt->flags = flags;
 }
 
drivers/staging/olpc_dcon/olpc_dcon.c +1 -1
diff -u -p a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -576,7 +576,7 @@ static struct notifier_block dcon_panic_
 
 static int dcon_detect(struct i2c_client *client, struct i2c_board_info *info)
 {
-	strlcpy(info->type, "olpc_dcon", I2C_NAME_SIZE);
+	stracpy(info->type, "olpc_dcon");
 
 	return 0;
 }
net/core/netpoll.c +1 -1
diff -u -p a/net/core/netpoll.c b/net/core/netpoll.c
@@ -588,7 +588,7 @@ int __netpoll_setup(struct netpoll *np,
 	int err;
 
 	np->dev = ndev;
-	strlcpy(np->dev_name, ndev->name, IFNAMSIZ);
+	stracpy(np->dev_name, ndev->name);
 
 	if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
 		np_err(np, "%s doesn't support polling, aborting\n",

// spatch.opt -j 44 ~/linux-next stracpy.cocci --recursive-includes --include-headers-for-types --very-quiet > stracpy.out

@r@
identifier f,i1,i2;
struct i1 e1;
expression e2;
position p;
@@
\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

@@
identifier r.i1,r.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

@@
identifier f,i2,i1;
struct i1 e1;
expression e2;
local idexpression x;
position r.p;
@@
(
-x = strlcpy
+stracpy
(e1.f, e2
- , i2
)@p;
... when != x

|
-strlcpy
+stracpy
(e1.f, e2
- , i2
)@p;
|
-strscpy
+stracpy
(e1.f, e2
- , i2
)@p
... when any
)

#25 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 3 lines

New version. I check for non-use of the return value of strlcpy and address some issues that affected the matching of the case where the first argument involves a pointer dereference.

I suggest to take another look at corresponding implementation details of the shown SmPL script.

Quoted 1 line

\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

Can the data access operator “->” (arrow) matter also here?

Quoted 5 lines

@@
identifier r.i1,r.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

Will an additional SmPL rule name be helpful for this part?

Quoted 10 lines

@@
(

(quoted diff) +1 -2
-x = strlcpy
+stracpy
  (e1.f, e2
-    , i2
  )@p;
  ... when != x

|

I wonder about the deletion of the assignment target. Should the setting of such a variable be usually preserved?

Regards,
Markus

#26 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 11 lines · Markus Elfring
Quoted 3 lines

New version. I check for non-use of the return value of strlcpy and address some issues that affected the matching of the case where the first argument involves a pointer dereference.

I suggest to take another look at corresponding implementation details of the shown SmPL script.

Quoted 1 line

\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

Can the data access operator “->” (arrow) matter also here?

What did my email say about isomorphisms?

Quoted 9 lines
Quoted 7 lines

@@
identifier r.i1,r.i2;
type T;
@@
struct i1 { ... T i1[i2]; ... }

Will an additional SmPL rule name be helpful for this part?

Yes, sorry, it would seem that that is necessary. I will fix and resend the results.

Quoted 11 lines
Quoted 11 lines

@@
(

(quoted diff) +1 -2
-x = strlcpy
+stracpy
  (e1.f, e2
-    , i2
  )@p;
  ... when != x
Quoted 4 lines
Quoted 1 line

|

I wonder about the deletion of the assignment target. Should the setting of such a variable be usually preserved?

If it is a local variable and never subsequently used, it doesn't seem very useful.

julia

#27 lore raw

Re: [1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

@@
(

(quoted diff) +1 -2
-x = strlcpy
+stracpy
  (e1.f, e2
-    , i2
  )@p;
  ... when != x
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

|

I wonder about the deletion of the assignment target. Should the setting of such a variable be usually preserved?

If it is a local variable and never subsequently used, it doesn't seem very useful.

Such an explanation is easier to understand.

* How do you think about the possibility that it was (accidentally) forgotten to use such a local variable?

* Your transformation can result in an intentionally unused return value. Would you like point any more source code places out
where values are unused so far?

Regards,
Markus

#28 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

In reply to Julia Lawall
Quoted 7 lines

@r@
identifier f,i1,i2;
struct i1 e1;
expression e2;
position p;
@@
\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

I have got the impression that the replacement can work also without an inherited position variable at the end. How do you think about to omit this SmPL rule then?

Can it be nicer to reduce duplicate SmPL code a bit?

Regards,
Markus

#29 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 8 lines · Markus Elfring
Quoted 7 lines

@r@
identifier f,i1,i2;
struct i1 e1;
expression e2;
position p;
@@
\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

Quoted 5 lines

I have got the impression that the replacement can work also without an inherited position variable at the end. How do you think about to omit this SmPL rule then?

Can it be nicer to reduce duplicate SmPL code a bit?

Huh? Rule 2 is important, to ensure that ths size is correct. Without rule 1, how can rule 2 be checked?

julia

#30 lore raw

Re: [1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 1 line

Huh? Rule 2 is important, to ensure that ths size is correct.

I assume that the dependency of the replacement on the data structure check can become clearer.

Regards,
Markus

#31 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

In reply to Julia Lawall
Quoted 7 lines · Julia Lawall

New version. I check for non-use of the return value of strlcpy and address some issues that affected the matching of the case where the first argument involves a pointer dereference. Actually, an isomorphism now takes care of that case, so it doesn't show up in the semantic patch explicitly any more.

julia

Nice x 2, thanks again.

More comments:

@@
identifier f,i2,i1;
struct i1 e1;
expression e2;
local idexpression x;
position r.p;
@@
(
-x = strlcpy
+stracpy
(e1.f, e2
- , i2
)@p;
... when != x

Just for completeness and correctness, as I at least don't find an existing use:

Perhaps this "x =" should also include += and + and the various other operators that are possible or does SmPL grammar already do that?

Also, it might be nice to include the trivial conversion with sizeof(e1) and ARRAY_SIZE(e1) so a single script could be run over the kernel.

I'll see about adding that and try it myself so an automated conversion should be possible.

#32 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 10 lines · Joe Perches
Quoted 7 lines · Julia Lawall

New version. I check for non-use of the return value of strlcpy and address some issues that affected the matching of the case where the first argument involves a pointer dereference. Actually, an isomorphism now takes care of that case, so it doesn't show up in the semantic patch explicitly any more.

julia

Nice x 2, thanks again.

Not quite nice due to the ignoring of rule 2 noticed by Markus. There is actually currently no guarantee that the size is right. I'm testing a new version.

Quoted 18 lines

More comments:

@@
identifier f,i2,i1;
struct i1 e1;
expression e2;
local idexpression x;
position r.p;
@@
(

(quoted diff) +1 -2
-x = strlcpy
+stracpy
  (e1.f, e2
-    , i2
  )@p;
  ... when != x
Quoted 6 lines

Just for completeness and correctness, as I at least don't find an existing use:

Perhaps this "x =" should also include += and + and the various other operators that are possible or does SmPL grammar already do that?

I could do this. One might though think that if someone went to the trouble of computing +=, these would be cases that we don't want to change? Still, it's not problem to add all assignment operators.

Quoted 3 lines

Also, it might be nice to include the trivial conversion with sizeof(e1) and ARRAY_SIZE(e1) so a single script could be run over the kernel.

Sure, I'll do that when all this is working. I didn't want those results to drown out these ones.

thanks,
julia

Quoted 6 lines

I'll see about adding that and try it myself so an automated conversion should be possible.

#33 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 1 line · Julia Lawall

On Thu, 25 Jul 2019, Joe Perches wrote:

[]

Quoted 10 lines
Quoted 6 lines

Just for completeness and correctness, as I at
least don't find an existing use:

Perhaps this "x =" should also include += and +
and the various other operators that are possible
or does SmPL grammar already do that?

I could do this. One might though think that if someone went to the trouble of computing +=, these would be cases that we don't want to change?

Maybe I quoted the wrong bit. But exactly.

Anywhere the return value of strlcpy is used, not just as an assignment, is an instance that should not be changed.

Thanks for doing this.

#34 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Perhaps this "x =" should also include += and +
and the various other operators that are possible
or does SmPL grammar already do that?

This is now done. It seems to have had no impact.

Quoted 2 lines

Anywhere the return value of strlcpy is used, not just as an assignment, is an instance that should not be changed.

Mostly what is changed for strlcpy is the case where there is a ; after the call, so that is not going to match an if test, etc. It also doesn't match the right side of an assignment. The only case of an assignment that is matched is when the variable is not used afterwards.

The rule now properly checks that the third argument is the size of the first argument. This made a small reduction in the number of results.

julia

// spatch.opt -j 44 ~/linux-next stracpy.cocci --recursive-includes --very-quiet > stracpy.out

@r@
identifier f,i1,i2;
struct i1 e1;
expression e2;
position p;
@@
\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

@ok@
identifier r.i1,r.i2,r.f;
type T;
@@
struct i1 { ... T f[i2]; ... }

@depends on ok@
identifier f,i2,i1;
struct i1 e1;
expression e2;
local idexpression x;
position r.p;
assignment operator aop;
@@
(
-x aop strlcpy
+stracpy
(e1.f, e2
- , i2
)@p;
... when != x

|
-strlcpy
+stracpy
(e1.f, e2
- , i2
)@p;
|
-strscpy
+stracpy
(e1.f, e2
- , i2
)@p
... when any
)

drivers/gpu/drm/drm_client.c +1 -1
diff -u -p a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c
@@ -347,7 +347,7 @@ static int drm_client_buffer_addfb(struc
 	/* drop the reference we picked up in framebuffer lookup */
 	drm_framebuffer_put(buffer->fb);
 
-	strscpy(buffer->fb->comm, client->name, TASK_COMM_LEN);
+	stracpy(buffer->fb->comm, client->name);
 
 	return 0;
 }
drivers/hwmon/max6639.c +1 -1
diff -u -p a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
@@ -511,7 +511,7 @@ static int max6639_detect(struct i2c_cli
 	if (dev_id != 0x58 || manu_id != 0x4D)
 		return -ENODEV;
 
-	strlcpy(info->type, "max6639", I2C_NAME_SIZE);
+	stracpy(info->type, "max6639");
 
 	return 0;
 }
drivers/media/dvb-frontends/cxd2820r_core.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -527,7 +527,7 @@ struct dvb_frontend *cxd2820r_attach(con
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "cxd2820r", I2C_NAME_SIZE);
+	stracpy(board_info.type, "cxd2820r");
 	board_info.addr = config->i2c_address;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(adapter, &board_info);
drivers/s390/cio/qdio_debug.c +1 -1
diff -u -p a/drivers/s390/cio/qdio_debug.c b/drivers/s390/cio/qdio_debug.c
@@ -101,7 +101,7 @@ int qdio_allocate_dbf(struct qdio_initia
 			debug_unregister(irq_ptr->debug_area);
 			return -ENOMEM;
 		}
-		strlcpy(new_entry->dbf_name, text, QDIO_DBF_NAME_LEN);
+		stracpy(new_entry->dbf_name, text);
 		new_entry->dbf_info = irq_ptr->debug_area;
 		mutex_lock(&qdio_dbf_list_mutex);
 		list_add(&new_entry->dbf_list, &qdio_dbf_list);
drivers/staging/comedi/comedi_fops.c +2 -2
diff -u -p a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
@@ -937,8 +937,8 @@ static int do_devinfo_ioctl(struct comed
 	/* fill devinfo structure */
 	devinfo.version_code = COMEDI_VERSION_CODE;
 	devinfo.n_subdevs = dev->n_subdevices;
-	strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN);
-	strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN);
+	stracpy(devinfo.driver_name, dev->driver->driver_name);
+	stracpy(devinfo.board_name, dev->board_name);
 
 	s = comedi_file_read_subdevice(file);
 	if (s)
crypto/api.c +1 -1
diff -u -p a/crypto/api.c b/crypto/api.c
@@ -115,7 +115,7 @@ struct crypto_larval *crypto_larval_allo
 	larval->alg.cra_priority = -1;
 	larval->alg.cra_destroy = crypto_larval_destroy;
 
-	strlcpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME);
+	stracpy(larval->alg.cra_name, name);
 	init_completion(&larval->completion);
 
 	return larval;
drivers/hwmon/adm1026.c +1 -1
diff -u -p a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
@@ -1610,7 +1610,7 @@ static int adm1026_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "adm1026", I2C_NAME_SIZE);
+	stracpy(info->type, "adm1026");
 
 	return 0;
 }
drivers/hwmon/tmp421.c +1 -1
diff -u -p a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
@@ -266,7 +266,7 @@ static int tmp421_detect(struct i2c_clie
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, tmp421_id[kind].name, I2C_NAME_SIZE);
+	stracpy(info->type, tmp421_id[kind].name);
 	dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n",
 		 names[kind], client->addr);
 
net/bridge/br_sysfs_if.c +2 -2
diff -u -p a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
@@ -374,7 +374,7 @@ int br_sysfs_addif(struct net_bridge_por
 			return err;
 	}
 
-	strlcpy(p->sysfs_name, p->dev->name, IFNAMSIZ);
+	stracpy(p->sysfs_name, p->dev->name);
 	return sysfs_create_link(br->ifobj, &p->kobj, p->sysfs_name);
 }
 
@@ -396,7 +396,7 @@ int br_sysfs_renameif(struct net_bridge_
 		netdev_notice(br->dev, "unable to rename link %s to %s",
 			      p->sysfs_name, p->dev->name);
 	else
-		strlcpy(p->sysfs_name, p->dev->name, IFNAMSIZ);
+		stracpy(p->sysfs_name, p->dev->name);
 
 	return err;
 }
drivers/hwmon/jc42.c +1 -1
diff -u -p a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
@@ -431,7 +431,7 @@ static int jc42_detect(struct i2c_client
 		struct jc42_chips *chip = &jc42_chips[i];
 		if (manid == chip->manid &&
 		    (devid & chip->devid_mask) == chip->devid) {
-			strlcpy(info->type, "jc42", I2C_NAME_SIZE);
+			stracpy(info->type, "jc42");
 			return 0;
 		}
 	}
drivers/hwmon/lm73.c +1 -1
diff -u -p a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
@@ -257,7 +257,7 @@ static int lm73_detect(struct i2c_client
 	if (id < 0 || id != LM73_ID)
 		return -ENODEV;
 
-	strlcpy(info->type, "lm73", I2C_NAME_SIZE);
+	stracpy(info->type, "lm73");
 
 	return 0;
 }
drivers/media/usb/dvb-usb-v2/af9035.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -189,7 +189,7 @@ static int af9035_add_i2c_dev(struct dvb
 		.platform_data = platform_data,
 	};
 
-	strscpy(board_info.type, type, I2C_NAME_SIZE);
+	stracpy(board_info.type, type);
 
 	/* find first free client */
 	for (num = 0; num < AF9035_I2C_CLIENT_MAX; num++) {
drivers/hwmon/adt7462.c +1 -1
diff -u -p a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c
@@ -1782,7 +1782,7 @@ static int adt7462_detect(struct i2c_cli
 	if (revision != ADT7462_REVISION)
 		return -ENODEV;
 
-	strlcpy(info->type, "adt7462", I2C_NAME_SIZE);
+	stracpy(info->type, "adt7462");
 
 	return 0;
 }
drivers/hwmon/smsc47m192.c +1 -1
diff -u -p a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
@@ -582,7 +582,7 @@ static int smsc47m192_detect(struct i2c_
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "smsc47m192", I2C_NAME_SIZE);
+	stracpy(info->type, "smsc47m192");
 
 	return 0;
 }
drivers/leds/leds-blinkm.c +1 -1
diff -u -p a/drivers/leds/leds-blinkm.c b/drivers/leds/leds-blinkm.c
@@ -562,7 +562,7 @@ static int blinkm_detect(struct i2c_clie
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "blinkm", I2C_NAME_SIZE);
+	stracpy(info->type, "blinkm");
 	return 0;
 }
 
drivers/media/pci/cx23885/cx23885-dvb.c +27 -27

216 lines not on this page · raw message

net/ipv4/ip_tunnel.c +1 -1
diff -u -p a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
@@ -1054,7 +1054,7 @@ int ip_tunnel_init_net(struct net *net,
 
 	memset(&parms, 0, sizeof(parms));
 	if (devname)
-		strlcpy(parms.name, devname, IFNAMSIZ);
+		stracpy(parms.name, devname);
 
 	rtnl_lock();
 	itn->fb_tunnel_dev = __ip_tunnel_create(net, ops, &parms);
drivers/hwmon/emc1403.c +6 -6
diff -u -p a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
@@ -329,22 +329,22 @@ static int emc1403_detect(struct i2c_cli
 	id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG);
 	switch (id) {
 	case 0x20:
-		strlcpy(info->type, "emc1402", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1402");
 		break;
 	case 0x21:
-		strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1403");
 		break;
 	case 0x22:
-		strlcpy(info->type, "emc1422", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1422");
 		break;
 	case 0x23:
-		strlcpy(info->type, "emc1423", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1423");
 		break;
 	case 0x25:
-		strlcpy(info->type, "emc1404", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1404");
 		break;
 	case 0x27:
-		strlcpy(info->type, "emc1424", I2C_NAME_SIZE);
+		stracpy(info->type, "emc1424");
 		break;
 	default:
 		return -ENODEV;
drivers/hwmon/w83l786ng.c +1 -1
diff -u -p a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
@@ -687,7 +687,7 @@ w83l786ng_detect(struct i2c_client *clie
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "w83l786ng", I2C_NAME_SIZE);
+	stracpy(info->type, "w83l786ng");
 
 	return 0;
 }
drivers/hwmon/lm77.c +1 -1
diff -u -p a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
@@ -302,7 +302,7 @@ static int lm77_detect(struct i2c_client
 	 || i2c_smbus_read_word_data(client, 7) != min)
 		return -ENODEV;
 
-	strlcpy(info->type, "lm77", I2C_NAME_SIZE);
+	stracpy(info->type, "lm77");
 
 	return 0;
 }
include/rdma/rdma_vt.h +1 -1
diff -u -p a/include/rdma/rdma_vt.h b/include/rdma/rdma_vt.h
@@ -486,7 +486,7 @@ static inline void rvt_set_ibdev_name(st
 	 * to work by setting the name manually here.
 	 */
 	dev_set_name(&rdi->ibdev.dev, fmt, name, unit);
-	strlcpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev), IB_DEVICE_NAME_MAX);
+	stracpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev));
 }
 
 /**
kernel/workqueue.c +1 -1
diff -u -p a/kernel/workqueue.c b/kernel/workqueue.c
@@ -2208,7 +2208,7 @@ __acquires(&pool->lock)
 	 * Record wq name for cmdline and debug reporting, may get
 	 * overridden through set_worker_desc().
 	 */
-	strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN);
+	stracpy(worker->desc, pwq->wq->name);
 
 	list_del_init(&work->entry);
 
drivers/hwmon/ftsteutates.c +1 -1
diff -u -p a/drivers/hwmon/ftsteutates.c b/drivers/hwmon/ftsteutates.c
@@ -739,7 +739,7 @@ static int fts_detect(struct i2c_client
 	if (val != 0x11)
 		return -ENODEV;
 
-	strlcpy(info->type, fts_id[0].name, I2C_NAME_SIZE);
+	stracpy(info->type, fts_id[0].name);
 	info->flags = 0;
 	return 0;
 }
drivers/media/i2c/tvaudio.c +1 -1
diff -u -p a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
@@ -1981,7 +1981,7 @@ static int tvaudio_probe(struct i2c_clie
 
 	/* fill required data structures */
 	if (!id)
-		strscpy(client->name, desc->name, I2C_NAME_SIZE);
+		stracpy(client->name, desc->name);
 	chip->desc = desc;
 	chip->shadow.count = desc->registers+1;
 	chip->prevmode = -1;
drivers/media/pci/saa7134/saa7134-input.c +1 -1
diff -u -p a/drivers/media/pci/saa7134/saa7134-input.c b/drivers/media/pci/saa7134/saa7134-input.c
@@ -856,7 +856,7 @@ void saa7134_probe_i2c_ir(struct saa7134
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	memset(&dev->init_data, 0, sizeof(dev->init_data));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (dev->board) {
 	case SAA7134_BOARD_PINNACLE_PCTV_110i:
drivers/media/usb/cx231xx/cx231xx-input.c +1 -1
diff -u -p a/drivers/media/usb/cx231xx/cx231xx-input.c b/drivers/media/usb/cx231xx/cx231xx-input.c
@@ -67,7 +67,7 @@ int cx231xx_ir_init(struct cx231xx *dev)
 
 	dev->init_data.name = cx231xx_boards[dev->model].name;
 
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 	info.platform_data = &dev->init_data;
 
 	/*
sound/ppc/keywest.c +1 -1
diff -u -p a/sound/ppc/keywest.c b/sound/ppc/keywest.c
@@ -48,7 +48,7 @@ static int keywest_attach_adapter(struct
 		return -EINVAL; /* ignored */
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strlcpy(info.type, "keywest", I2C_NAME_SIZE);
+	stracpy(info.type, "keywest");
 	info.addr = keywest_ctx->addr;
 	keywest_ctx->client = i2c_new_device(adapter, &info);
 	if (!keywest_ctx->client)
drivers/hwmon/lm87.c +1 -1
diff -u -p a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
@@ -833,7 +833,7 @@ static int lm87_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/media/pci/cx88/cx88-input.c +2 -2
diff -u -p a/drivers/media/pci/cx88/cx88-input.c b/drivers/media/pci/cx88/cx88-input.c
@@ -600,7 +600,7 @@ void cx88_i2c_init_ir(struct cx88_core *
 		return;
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (core->boardnr) {
 	case CX88_BOARD_LEADTEK_PVR2000:
@@ -625,7 +625,7 @@ void cx88_i2c_init_ir(struct cx88_core *
 
 		if (*addrp == 0x71) {
 			/* Hauppauge Z8F0811 */
-			strscpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE);
+			stracpy(info.type, "ir_z8f0811_haup");
 			core->init_data.name = core->board.name;
 			core->init_data.ir_codes = RC_MAP_HAUPPAUGE;
 			core->init_data.type = RC_PROTO_BIT_RC5 |
drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c +2 -2
diff -u -p a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
@@ -561,7 +561,7 @@ static void pvr2_i2c_register_ir(struct
 		/* IR Receiver */
 		info.addr          = 0x18;
 		info.platform_data = init_data;
-		strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_video");
 		pvr2_trace(PVR2_TRACE_INFO, "Binding %s to i2c address 0x%02x.",
 			   info.type, info.addr);
 		i2c_new_device(&hdw->i2c_adap, &info);
@@ -576,7 +576,7 @@ static void pvr2_i2c_register_ir(struct
 		/* IR Transceiver */
 		info.addr = 0x71;
 		info.platform_data = init_data;
-		strscpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_z8f0811_haup");
 		pvr2_trace(PVR2_TRACE_INFO, "Binding %s to i2c address 0x%02x.",
 			   info.type, info.addr);
 		i2c_new_device(&hdw->i2c_adap, &info);
drivers/s390/block/dasd_devmap.c +1 -1
diff -u -p a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
@@ -426,7 +426,7 @@ dasd_add_busid(const char *bus_id, int f
 	if (!devmap) {
 		/* This bus_id is new. */
 		new->devindex = dasd_max_devindex++;
-		strlcpy(new->bus_id, bus_id, DASD_BUS_ID_SIZE);
+		stracpy(new->bus_id, bus_id);
 		new->features = features;
 		new->device = NULL;
 		list_add(&new->list, &dasd_hashlists[hash]);
drivers/usb/usbip/stub_main.c +1 -1
diff -u -p a/drivers/usb/usbip/stub_main.c b/drivers/usb/usbip/stub_main.c
@@ -101,7 +101,7 @@ static int add_match_busid(char *busid)
 	for (i = 0; i < MAX_BUSID; i++) {
 		spin_lock(&busid_table[i].busid_lock);
 		if (!busid_table[i].name[0]) {
-			strlcpy(busid_table[i].name, busid, BUSID_SIZE);
+			stracpy(busid_table[i].name, busid);
 			if ((busid_table[i].status != STUB_BUSID_ALLOC) &&
 			    (busid_table[i].status != STUB_BUSID_REMOV))
 				busid_table[i].status = STUB_BUSID_ADDED;
net/core/dev.c +3 -3
diff -u -p a/net/core/dev.c b/net/core/dev.c
@@ -572,7 +572,7 @@ static int netdev_boot_setup_add(char *n
 	for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
 		if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
 			memset(s[i].name, 0, sizeof(s[i].name));
-			strlcpy(s[i].name, name, IFNAMSIZ);
+			stracpy(s[i].name, name);
 			memcpy(&s[i].map, map, sizeof(s[i].map));
 			break;
 		}
@@ -1117,7 +1117,7 @@ static int dev_alloc_name_ns(struct net
 	BUG_ON(!net);
 	ret = __dev_alloc_name(net, name, buf);
 	if (ret >= 0)
-		strlcpy(dev->name, buf, IFNAMSIZ);
+		stracpy(dev->name, buf);
 	return ret;
 }
 
@@ -1154,7 +1154,7 @@ int dev_get_valid_name(struct net *net,
 	else if (__dev_get_by_name(net, name))
 		return -EEXIST;
 	else if (dev->name != name)
-		strlcpy(dev->name, name, IFNAMSIZ);
+		stracpy(dev->name, name);
 
 	return 0;
 }
drivers/hwmon/asb100.c +1 -1
diff -u -p a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
@@ -770,7 +770,7 @@ static int asb100_detect(struct i2c_clie
 	if (val1 != 0x31 || val2 != 0x06)
 		return -ENODEV;
 
-	strlcpy(info->type, "asb100", I2C_NAME_SIZE);
+	stracpy(info->type, "asb100");
 
 	return 0;
 }
drivers/hwmon/w83l785ts.c +1 -1
diff -u -p a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
@@ -158,7 +158,7 @@ static int w83l785ts_detect(struct i2c_c
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "w83l785ts", I2C_NAME_SIZE);
+	stracpy(info->type, "w83l785ts");
 
 	return 0;
 }
include/rdma/rdma_vt.h +1 -1
diff -u -p a/include/rdma/rdma_vt.h b/include/rdma/rdma_vt.h
@@ -486,7 +486,7 @@ static inline void rvt_set_ibdev_name(st
 	 * to work by setting the name manually here.
 	 */
 	dev_set_name(&rdi->ibdev.dev, fmt, name, unit);
-	strlcpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev), IB_DEVICE_NAME_MAX);
+	stracpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev));
 }
 
 /**
drivers/scsi/bfa/bfad_bsg.c +2 -2
diff -u -p a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
@@ -119,8 +119,8 @@ bfad_iocmd_ioc_get_attr(struct bfad_s *b
 
 	/* fill in driver attr info */
 	strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME);
-	strlcpy(iocmd->ioc_attr.driver_attr.driver_ver,
-		BFAD_DRIVER_VERSION, BFA_VERSION_LEN);
+	stracpy(iocmd->ioc_attr.driver_attr.driver_ver,
+		BFAD_DRIVER_VERSION);
 	strcpy(iocmd->ioc_attr.driver_attr.fw_ver,
 		iocmd->ioc_attr.adapter_attr.fw_ver);
 	strcpy(iocmd->ioc_attr.driver_attr.bios_ver,
drivers/staging/olpc_dcon/olpc_dcon.c +1 -1
diff -u -p a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -576,7 +576,7 @@ static struct notifier_block dcon_panic_
 
 static int dcon_detect(struct i2c_client *client, struct i2c_board_info *info)
 {
-	strlcpy(info->type, "olpc_dcon", I2C_NAME_SIZE);
+	stracpy(info->type, "olpc_dcon");
 
 	return 0;
 }
drivers/acpi/processor_idle.c +4 -5
diff -u -p a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
@@ -865,7 +865,7 @@ static int acpi_processor_setup_cstates(
 
 		state = &drv->states[count];
 		snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
-		strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
+		stracpy(state->desc, cx->desc);
 		state->exit_latency = cx->latency;
 		state->target_residency = cx->latency * latency_factor;
 		state->enter = acpi_idle_enter;
@@ -1036,8 +1036,7 @@ static int acpi_processor_evaluate_lpi(a
 
 		obj = pkg_elem + 9;
 		if (obj->type == ACPI_TYPE_STRING)
-			strlcpy(lpi_state->desc, obj->string.pointer,
-				ACPI_CX_DESC_LEN);
+			stracpy(lpi_state->desc, obj->string.pointer);
 
 		lpi_state->index = state_idx;
 		if (obj_get_integer(pkg_elem + 0, &lpi_state->min_residency)) {
@@ -1102,7 +1101,7 @@ static bool combine_lpi_states(struct ac
 	result->arch_flags = parent->arch_flags;
 	result->index = parent->index;
 
-	strlcpy(result->desc, local->desc, ACPI_CX_DESC_LEN);
+	stracpy(result->desc, local->desc);
 	strlcat(result->desc, "+", ACPI_CX_DESC_LEN);
 	strlcat(result->desc, parent->desc, ACPI_CX_DESC_LEN);
 	return true;
@@ -1271,7 +1270,7 @@ static int acpi_processor_setup_lpi_stat
 
 		state = &drv->states[i];
 		snprintf(state->name, CPUIDLE_NAME_LEN, "LPI-%d", i);
-		strlcpy(state->desc, lpi->desc, CPUIDLE_DESC_LEN);
+		stracpy(state->desc, lpi->desc);
 		state->exit_latency = lpi->wake_latency;
 		state->target_residency = lpi->min_residency;
 		if (lpi->arch_flags)
drivers/hwmon/f75375s.c +1 -1
diff -u -p a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
@@ -899,7 +899,7 @@ static int f75375_detect(struct i2c_clie
 
 	version = f75375_read8(client, F75375_REG_VERSION);
 	dev_info(&adapter->dev, "found %s version: %02X\n", name, version);
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/media/dvb-core/dvbdev.c +2 -2
diff -u -p a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
@@ -975,9 +975,9 @@ struct i2c_client *dvb_module_probe(cons
 		return NULL;
 
 	if (name)
-		strscpy(board_info->type, name, I2C_NAME_SIZE);
+		stracpy(board_info->type, name);
 	else
-		strscpy(board_info->type, module_name, I2C_NAME_SIZE);
+		stracpy(board_info->type, module_name);
 
 	board_info->addr = addr;
 	board_info->platform_data = platform_data;
drivers/hwmon/max1668.c +1 -1
diff -u -p a/drivers/hwmon/max1668.c b/drivers/hwmon/max1668.c
@@ -386,7 +386,7 @@ static int max1668_detect(struct i2c_cli
 	if (!type_name)
 		return -ENODEV;
 
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
net/sched/sch_teql.c +1 -1
diff -u -p a/net/sched/sch_teql.c b/net/sched/sch_teql.c
@@ -489,7 +489,7 @@ static int __init teql_init(void)
 
 		master = netdev_priv(dev);
 
-		strlcpy(master->qops.id, dev->name, IFNAMSIZ);
+		stracpy(master->qops.id, dev->name);
 		err = register_qdisc(&master->qops);
 
 		if (err) {
drivers/firmware/arm_scmi/sensors.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
@@ -146,7 +146,7 @@ static int scmi_sensor_description_get(c
 			/* Sign extend to a full s8 */
 			if (s->scale & SENSOR_SCALE_SIGN)
 				s->scale |= SENSOR_SCALE_EXTEND;
-			strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE);
+			stracpy(s->name, buf->desc[cnt].name);
 		}
 
 		desc_index += num_returned;
drivers/hwmon/adt7470.c +1 -1
diff -u -p a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
@@ -1200,7 +1200,7 @@ static int adt7470_detect(struct i2c_cli
 	if (revision != ADT7470_REVISION)
 		return -ENODEV;
 
-	strlcpy(info->type, "adt7470", I2C_NAME_SIZE);
+	stracpy(info->type, "adt7470");
 
 	return 0;
 }
drivers/hwmon/w83795.c +1 -1
diff -u -p a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
@@ -1967,7 +1967,7 @@ static int w83795_detect(struct i2c_clie
 	else
 		chip_name = "w83795g";
 
-	strlcpy(info->type, chip_name, I2C_NAME_SIZE);
+	stracpy(info->type, chip_name);
 	dev_info(&adapter->dev, "Found %s rev. %c at 0x%02hx\n", chip_name,
 		 'A' + (device_id & 0xf), address);
 
tools/perf/util/auxtrace.c +1 -1
diff -u -p a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
@@ -865,7 +865,7 @@ void auxtrace_synth_error(struct auxtrac
 	auxtrace_error->fmt = 1;
 	auxtrace_error->ip = ip;
 	auxtrace_error->time = timestamp;
-	strlcpy(auxtrace_error->msg, msg, MAX_AUXTRACE_ERROR_MSG);
+	stracpy(auxtrace_error->msg, msg);
 
 	size = (void *)auxtrace_error->msg - (void *)auxtrace_error +
 	       strlen(auxtrace_error->msg) + 1;
arch/mips/bcm47xx/board.c +1 -2
diff -u -p a/arch/mips/bcm47xx/board.c b/arch/mips/bcm47xx/board.c
@@ -344,8 +344,7 @@ void __init bcm47xx_board_detect(void)
 
 	board_detected = bcm47xx_board_get_nvram();
 	bcm47xx_board.board = board_detected->board;
-	strlcpy(bcm47xx_board.name, board_detected->name,
-		BCM47XX_BOARD_MAX_NAME);
+	stracpy(bcm47xx_board.name, board_detected->name);
 }
 
 enum bcm47xx_board bcm47xx_board_get(void)
drivers/hwmon/adt7411.c +1 -1
diff -u -p a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
@@ -590,7 +590,7 @@ static int adt7411_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "adt7411", I2C_NAME_SIZE);
+	stracpy(info->type, "adt7411");
 
 	return 0;
 }
drivers/hwmon/nct7802.c +1 -1
diff -u -p a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
@@ -959,7 +959,7 @@ static int nct7802_detect(struct i2c_cli
 	if (reg < 0 || (reg & 0x3f))
 		return -ENODEV;
 
-	strlcpy(info->type, "nct7802", I2C_NAME_SIZE);
+	stracpy(info->type, "nct7802");
 	return 0;
 }
 
drivers/media/pci/cx88/cx88-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx88/cx88-i2c.c b/drivers/media/pci/cx88/cx88-i2c.c
@@ -137,7 +137,7 @@ int cx88_i2c_init(struct cx88_core *core
 	i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev);
 	core->i2c_adap.algo_data = &core->i2c_algo;
 	core->i2c_client.adapter = &core->i2c_adap;
-	strscpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE);
+	stracpy(core->i2c_client.name, "cx88xx internal");
 
 	cx8800_bit_setscl(core, 1);
 	cx8800_bit_setsda(core, 1);
lib/earlycpio.c +1 -1
diff -u -p a/lib/earlycpio.c b/lib/earlycpio.c
@@ -126,7 +126,7 @@ struct cpio_data find_cpio_data(const ch
 				"File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",
 				p, MAX_CPIO_FILE_NAME);
 			}
-			strlcpy(cd.name, p + mypathsize, MAX_CPIO_FILE_NAME);
+			stracpy(cd.name, p + mypathsize);
 
 			cd.data = (void *)dptr;
 			cd.size = ch[C_FILESIZE];
drivers/hwmon/max1619.c +1 -1
diff -u -p a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
@@ -241,7 +241,7 @@ static int max1619_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "max1619", I2C_NAME_SIZE);
+	stracpy(info->type, "max1619");
 
 	return 0;
 }
drivers/media/usb/dvb-usb-v2/zd1301.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/zd1301.c b/drivers/media/usb/dvb-usb-v2/zd1301.c
@@ -168,7 +168,7 @@ static int zd1301_frontend_attach(struct
 	dev->mt2060_pdata.i2c_write_max = 9;
 	dev->mt2060_pdata.dvb_frontend = frontend;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "mt2060", I2C_NAME_SIZE);
+	stracpy(board_info.type, "mt2060");
 	board_info.addr = 0x60;
 	board_info.platform_data = &dev->mt2060_pdata;
 	request_module("%s", "mt2060");
drivers/scsi/qla4xxx/ql4_os.c +4 -6
diff -u -p a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
@@ -767,8 +767,7 @@ static int qla4xxx_get_chap_list(struct
 			continue;
 
 		chap_rec->chap_tbl_idx = i;
-		strlcpy(chap_rec->username, chap_table->name,
-			ISCSI_CHAP_AUTH_NAME_MAX_LEN);
+		stracpy(chap_rec->username, chap_table->name);
 		strlcpy(chap_rec->password, chap_table->secret,
 			QL4_CHAP_MAX_SECRET_LEN);
 		chap_rec->password_length = chap_table->secret_len;
@@ -6265,8 +6264,8 @@ static void qla4xxx_get_param_ddb(struct
 
 	tddb->tpgt = sess->tpgt;
 	tddb->port = conn->persistent_port;
-	strlcpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
-	strlcpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
+	stracpy(tddb->iscsi_name, sess->targetname);
+	stracpy(tddb->ip_addr, conn->persistent_address);
 }
 
 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
@@ -7769,8 +7768,7 @@ static int qla4xxx_sysfs_ddb_logout(stru
 		goto exit_ddb_logout;
 	}
 
-	strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
-		ISCSI_NAME_SIZE);
+	stracpy(flash_tddb->iscsi_name, fnode_sess->targetname);
 
 	if (!strncmp(fnode_sess->portal_type, PORTAL_TYPE_IPV6, 4))
 		sprintf(flash_tddb->ip_addr, "%pI6", fnode_conn->ipaddress);
drivers/hwmon/adm9240.c +1 -1
diff -u -p a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
@@ -657,7 +657,7 @@ static int adm9240_detect(struct i2c_cli
 		 man_id == 0x23 ? "ADM9240" :
 		 man_id == 0xda ? "DS1780" : "LM81", die_rev);
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/w83793.c +1 -1
diff -u -p a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
@@ -1651,7 +1651,7 @@ static int w83793_detect(struct i2c_clie
 	if (chip_id != 0x7b)
 		return -ENODEV;
 
-	strlcpy(info->type, "w83793", I2C_NAME_SIZE);
+	stracpy(info->type, "w83793");
 
 	return 0;
 }
drivers/media/pci/cx23885/cx23885-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx23885/cx23885-i2c.c b/drivers/media/pci/cx23885/cx23885-i2c.c
@@ -334,7 +334,7 @@ int cx23885_i2c_register(struct cx23885_
 		};
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
-		strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+		stracpy(info.type, "ir_video");
 		/* Use quick read command for probe, some IR chips don't
 		 * support writes */
 		i2c_new_probed_device(&bus->i2c_adap, &info, addr_list,
drivers/hwmon/lm78.c +1 -1
diff -u -p a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
@@ -617,7 +617,7 @@ static int lm78_i2c_detect(struct i2c_cl
 	if (isa)
 		mutex_unlock(&isa->update_lock);
 
-	strlcpy(info->type, client_name, I2C_NAME_SIZE);
+	stracpy(info->type, client_name);
 
 	return 0;
 
include/rdma/rdma_vt.h +1 -1
diff -u -p a/include/rdma/rdma_vt.h b/include/rdma/rdma_vt.h
@@ -486,7 +486,7 @@ static inline void rvt_set_ibdev_name(st
 	 * to work by setting the name manually here.
 	 */
 	dev_set_name(&rdi->ibdev.dev, fmt, name, unit);
-	strlcpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev), IB_DEVICE_NAME_MAX);
+	stracpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev));
 }
 
 /**
kernel/cgroup/cgroup.c +2 -2
diff -u -p a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
@@ -1980,9 +1980,9 @@ void init_cgroup_root(struct cgroup_fs_c
 
 	root->flags = ctx->flags;
 	if (ctx->release_agent)
-		strscpy(root->release_agent_path, ctx->release_agent, PATH_MAX);
+		stracpy(root->release_agent_path, ctx->release_agent);
 	if (ctx->name)
-		strscpy(root->name, ctx->name, MAX_CGROUP_ROOT_NAMELEN);
+		stracpy(root->name, ctx->name);
 	if (ctx->cpuset_clone_children)
 		set_bit(CGRP_CPUSET_CLONE_CHILDREN, &root->cgrp.flags);
 }
drivers/cpuidle/cpuidle-powernv.c +1 -1
diff -u -p a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
@@ -236,7 +236,7 @@ static inline void add_powernv_state(int
 				     unsigned int exit_latency,
 				     u64 psscr_val, u64 psscr_mask)
 {
-	strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);
+	stracpy(powernv_states[index].name, name);
 	strlcpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN);
 	powernv_states[index].flags = flags;
 	powernv_states[index].target_residency = target_residency;
drivers/hwmon/asc7621.c +1 -2
diff -u -p a/drivers/hwmon/asc7621.c b/drivers/hwmon/asc7621.c
@@ -1153,8 +1153,7 @@ static int asc7621_detect(struct i2c_cli
 
 		if (company == asc7621_chips[chip_index].company_id &&
 		    verstep == asc7621_chips[chip_index].verstep_id) {
-			strlcpy(info->type, asc7621_chips[chip_index].name,
-				I2C_NAME_SIZE);
+			stracpy(info->type, asc7621_chips[chip_index].name);
 
 			dev_info(&adapter->dev, "Matched %s at 0x%02x\n",
 				 asc7621_chips[chip_index].name, client->addr);
drivers/hwmon/nct7904.c +1 -1
diff -u -p a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
@@ -397,7 +397,7 @@ static int nct7904_detect(struct i2c_cli
 	    (i2c_smbus_read_byte_data(client, BANK_SEL_REG) & 0xf8) != 0x00)
 		return -ENODEV;
 
-	strlcpy(info->type, "nct7904", I2C_NAME_SIZE);
+	stracpy(info->type, "nct7904");
 
 	return 0;
 }
drivers/media/usb/dvb-usb-v2/anysee.c +1 -1
diff -u -p a/drivers/media/usb/dvb-usb-v2/anysee.c b/drivers/media/usb/dvb-usb-v2/anysee.c
@@ -629,7 +629,7 @@ static int anysee_add_i2c_dev(struct dvb
 		.platform_data = platform_data,
 	};
 
-	strscpy(board_info.type, type, I2C_NAME_SIZE);
+	stracpy(board_info.type, type);
 
 	/* find first free client */
 	for (num = 0; num < ANYSEE_I2C_CLIENT_MAX; num++) {
drivers/nvme/host/fabrics.c +1 -1
diff -u -p a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
@@ -49,7 +49,7 @@ static struct nvmf_host *nvmf_host_add(c
 		goto out_unlock;
 
 	kref_init(&host->ref);
-	strlcpy(host->nqn, hostnqn, NVMF_NQN_SIZE);
+	stracpy(host->nqn, hostnqn);
 
 	list_add_tail(&host->list, &nvmf_hosts);
 out_unlock:
drivers/hwmon/lm83.c +1 -1
diff -u -p a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
@@ -312,7 +312,7 @@ static int lm83_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/char/ipmi/ipmi_ssif.c +1 -1
diff -u -p a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
@@ -1397,7 +1397,7 @@ static int ssif_detect(struct i2c_client
 	if (rv)
 		rv = -ENODEV;
 	else
-		strlcpy(info->type, DEVICE_NAME, I2C_NAME_SIZE);
+		stracpy(info->type, DEVICE_NAME);
 	kfree(resp);
 	return rv;
 }
drivers/hwmon/gl518sm.c +1 -1
diff -u -p a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
@@ -586,7 +586,7 @@ static int gl518_detect(struct i2c_clien
 	if (rev != 0x00 && rev != 0x80)
 		return -ENODEV;
 
-	strlcpy(info->type, "gl518sm", I2C_NAME_SIZE);
+	stracpy(info->type, "gl518sm");
 
 	return 0;
 }
drivers/nvme/host/core.c +1 -1
diff -u -p a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
@@ -2292,7 +2292,7 @@ static void nvme_init_subnqn(struct nvme
 	if(!(ctrl->quirks & NVME_QUIRK_IGNORE_DEV_SUBNQN)) {
 		nqnlen = strnlen(id->subnqn, NVMF_NQN_SIZE);
 		if (nqnlen > 0 && nqnlen < NVMF_NQN_SIZE) {
-			strlcpy(subsys->subnqn, id->subnqn, NVMF_NQN_SIZE);
+			stracpy(subsys->subnqn, id->subnqn);
 			return;
 		}
 
drivers/hwmon/lm95234.c +1 -1
diff -u -p a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
@@ -644,7 +644,7 @@ static int lm95234_detect(struct i2c_cli
 	if (val & model_mask)
 		return -ENODEV;
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	return 0;
 }
 
drivers/net/ethernet/hp/hp100.c +1 -1
diff -u -p a/drivers/net/ethernet/hp/hp100.c b/drivers/net/ethernet/hp/hp100.c
@@ -643,7 +643,7 @@ static int hp100_probe1(struct net_devic
 	lp = netdev_priv(dev);
 
 	spin_lock_init(&lp->lock);
-	strlcpy(lp->id, eid, HP100_SIG_LEN);
+	stracpy(lp->id, eid);
 	lp->chip = chip;
 	lp->mode = local_mode;
 	lp->bus = bus;
drivers/scsi/bfa/bfa_fcs_lport.c +5 -5
diff -u -p a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -2655,13 +2655,13 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_
 	bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
 	hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
 
-	strlcpy(hba_attr->node_sym_name.symname,
-		port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
+	stracpy(hba_attr->node_sym_name.symname,
+		port->port_cfg.node_sym_name.symname);
 	strcpy(hba_attr->vendor_info, "QLogic");
 	hba_attr->num_ports =
 		cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
 	hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
-	strlcpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
+	stracpy(hba_attr->bios_ver, hba_attr->option_rom_ver);
 
 }
 
@@ -2740,8 +2740,8 @@ bfa_fcs_fdmi_get_portattr(struct bfa_fcs
 	port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
 	port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
 
-	strlcpy(port_attr->port_sym_name.symname,
-		bfa_fcs_lport_get_psym_name(port).symname, BFA_SYMNAME_MAXLEN);
+	stracpy(port_attr->port_sym_name.symname,
+		bfa_fcs_lport_get_psym_name(port).symname);
 	bfa_fcs_lport_get_attr(port, &lport_attr);
 	port_attr->port_type = cpu_to_be32(lport_attr.port_type);
 	port_attr->scos = pport_attr.cos_supported;
drivers/hwmon/adc128d818.c +1 -1
diff -u -p a/drivers/hwmon/adc128d818.c b/drivers/hwmon/adc128d818.c
@@ -384,7 +384,7 @@ static int adc128_detect(struct i2c_clie
 	if (i2c_smbus_read_byte_data(client, ADC128_REG_BUSY_STATUS) & 0xfc)
 		return -ENODEV;
 
-	strlcpy(info->type, "adc128d818", I2C_NAME_SIZE);
+	stracpy(info->type, "adc128d818");
 
 	return 0;
 }
drivers/hwmon/tmp401.c +1 -1
diff -u -p a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
@@ -678,7 +678,7 @@ static int tmp401_detect(struct i2c_clie
 	if (reg > 15)
 		return -ENODEV;
 
-	strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE);
+	stracpy(info->type, tmp401_id[kind].name);
 
 	return 0;
 }
drivers/net/netconsole.c +4 -4
diff -u -p a/drivers/net/netconsole.c b/drivers/net/netconsole.c
@@ -177,7 +177,7 @@ static struct netconsole_target *alloc_p
 		goto fail;
 
 	nt->np.name = "netconsole";
-	strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
+	stracpy(nt->np.dev_name, "eth0");
 	nt->np.local_port = 6665;
 	nt->np.remote_port = 6666;
 	eth_broadcast_addr(nt->np.remote_mac);
@@ -413,7 +413,7 @@ static ssize_t dev_name_store(struct con
 		return -EINVAL;
 	}
 
-	strlcpy(nt->np.dev_name, buf, IFNAMSIZ);
+	stracpy(nt->np.dev_name, buf);
 
 	/* Get rid of possible trailing newline from echo(1) */
 	len = strnlen(nt->np.dev_name, IFNAMSIZ);
@@ -629,7 +629,7 @@ static struct config_item *make_netconso
 		return ERR_PTR(-ENOMEM);
 
 	nt->np.name = "netconsole";
-	strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ);
+	stracpy(nt->np.dev_name, "eth0");
 	nt->np.local_port = 6665;
 	nt->np.remote_port = 6666;
 	eth_broadcast_addr(nt->np.remote_mac);
@@ -707,7 +707,7 @@ restart:
 		if (nt->np.dev == dev) {
 			switch (event) {
 			case NETDEV_CHANGENAME:
-				strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ);
+				stracpy(nt->np.dev_name, dev->name);
 				break;
 			case NETDEV_RELEASE:
 			case NETDEV_JOIN:
drivers/target/target_core_user.c +2 -2
diff -u -p a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
@@ -2344,14 +2344,14 @@ static ssize_t tcmu_dev_config_store(str
 			pr_err("Unable to reconfigure device\n");
 			return ret;
 		}
-		strlcpy(udev->dev_config, page, TCMU_CONFIG_LEN);
+		stracpy(udev->dev_config, page);
 
 		ret = tcmu_update_uio_info(udev);
 		if (ret)
 			return ret;
 		return count;
 	}
-	strlcpy(udev->dev_config, page, TCMU_CONFIG_LEN);
+	stracpy(udev->dev_config, page);
 
 	return count;
 }
sound/aoa/codecs/onyx.c +1 -1
diff -u -p a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
@@ -1011,7 +1011,7 @@ static int onyx_i2c_probe(struct i2c_cli
 		goto fail;
 	}
 
-	strlcpy(onyx->codec.name, "onyx", MAX_CODEC_NAME_LEN);
+	stracpy(onyx->codec.name, "onyx");
 	onyx->codec.owner = THIS_MODULE;
 	onyx->codec.init = onyx_init_codec;
 	onyx->codec.exit = onyx_exit_codec;
drivers/hwmon/lm90.c +1 -1
diff -u -p a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
@@ -1610,7 +1610,7 @@ static int lm90_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/lm85.c +1 -1
diff -u -p a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
@@ -1539,7 +1539,7 @@ static int lm85_detect(struct i2c_client
 	if (!type_name)
 		return -ENODEV;
 
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
drivers/media/pci/bt8xx/bttv-i2c.c +1 -1
diff -u -p a/drivers/media/pci/bt8xx/bttv-i2c.c b/drivers/media/pci/bt8xx/bttv-i2c.c
@@ -335,7 +335,7 @@ static void do_i2c_scan(char *name, stru
 /* init + register i2c adapter */
 int init_bttv_i2c(struct bttv *btv)
 {
-	strscpy(btv->i2c_client.name, "bttv internal", I2C_NAME_SIZE);
+	stracpy(btv->i2c_client.name, "bttv internal");
 
 	if (i2c_hw)
 		btv->use_i2c_hw = 1;
drivers/media/usb/dvb-usb/dib0700_devices.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/dib0700_devices.c b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -3760,7 +3760,7 @@ static int xbox_one_attach(struct dvb_us
 	mn88472_config.ts_mode = PARALLEL_TS_MODE;
 	mn88472_config.ts_clock = FIXED_TS_CLOCK;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "mn88472", I2C_NAME_SIZE);
+	stracpy(info.type, "mn88472");
 	info.addr = 0x18;
 	info.platform_data = &mn88472_config;
 	request_module(info.type);
@@ -3787,7 +3787,7 @@ static int xbox_one_attach(struct dvb_us
 	tda18250_config.fe = adap->fe_adap[0].fe;
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "tda18250", I2C_NAME_SIZE);
+	stracpy(info.type, "tda18250");
 	info.addr = 0x60;
 	info.platform_data = &tda18250_config;
 
drivers/hwmon/lm63.c +3 -3
diff -u -p a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
@@ -996,11 +996,11 @@ static int lm63_detect(struct i2c_client
 	}
 
 	if (chip_id == 0x41 && address == 0x4c)
-		strlcpy(info->type, "lm63", I2C_NAME_SIZE);
+		stracpy(info->type, "lm63");
 	else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e))
-		strlcpy(info->type, "lm64", I2C_NAME_SIZE);
+		stracpy(info->type, "lm64");
 	else if (chip_id == 0x49 && address == 0x4c)
-		strlcpy(info->type, "lm96163", I2C_NAME_SIZE);
+		stracpy(info->type, "lm96163");
 	else
 		return -ENODEV;
 
drivers/media/usb/dvb-usb-v2/rtl28xxu.c +9 -9
diff -u -p a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -693,7 +693,7 @@ static int rtl2831u_frontend_attach(stru
 
 	/* attach demodulator */
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
+	stracpy(board_info.type, "rtl2830");
 	board_info.addr = 0x10;
 	board_info.platform_data = pdata;
 	request_module("%s", board_info.type);
@@ -914,7 +914,7 @@ static int rtl2832u_frontend_attach(stru
 
 	/* attach demodulator */
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
+	stracpy(board_info.type, "rtl2832");
 	board_info.addr = 0x10;
 	board_info.platform_data = pdata;
 	request_module("%s", board_info.type);
@@ -953,7 +953,7 @@ static int rtl2832u_frontend_attach(stru
 
 			mn88472_config.fe = &adap->fe[1];
 			mn88472_config.i2c_wr_max = 22,
-			strscpy(info.type, "mn88472", I2C_NAME_SIZE);
+			stracpy(info.type, "mn88472");
 			mn88472_config.xtal = 20500000;
 			mn88472_config.ts_mode = SERIAL_TS_MODE;
 			mn88472_config.ts_clock = VARIABLE_TS_CLOCK;
@@ -978,7 +978,7 @@ static int rtl2832u_frontend_attach(stru
 
 			mn88473_config.fe = &adap->fe[1];
 			mn88473_config.i2c_wr_max = 22,
-			strscpy(info.type, "mn88473", I2C_NAME_SIZE);
+			stracpy(info.type, "mn88473");
 			info.addr = 0x18;
 			info.platform_data = &mn88473_config;
 			request_module(info.type);
@@ -1021,7 +1021,7 @@ static int rtl2832u_frontend_attach(stru
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			si2168_config.ts_clock_inv = false;
 			si2168_config.ts_clock_gapped = true;
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0x64;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -1212,7 +1212,7 @@ static int rtl2832u_tuner_attach(struct
 				.clock = 28800000,
 			};
 
-			strscpy(info.type, "e4000", I2C_NAME_SIZE);
+			stracpy(info.type, "e4000");
 			info.addr = 0x64;
 			info.platform_data = &e4000_config;
 
@@ -1236,7 +1236,7 @@ static int rtl2832u_tuner_attach(struct
 			};
 			struct i2c_board_info board_info = {};
 
-			strscpy(board_info.type, "fc2580", I2C_NAME_SIZE);
+			stracpy(board_info.type, "fc2580");
 			board_info.addr = 0x56;
 			board_info.platform_data = &fc2580_pdata;
 			request_module("fc2580");
@@ -1267,7 +1267,7 @@ static int rtl2832u_tuner_attach(struct
 		if (ret)
 			goto err;
 
-		strscpy(board_info.type, "tua9001", I2C_NAME_SIZE);
+		stracpy(board_info.type, "tua9001");
 		board_info.addr = 0x60;
 		board_info.platform_data = &tua9001_pdata;
 		request_module("tua9001");
@@ -1312,7 +1312,7 @@ static int rtl2832u_tuner_attach(struct
 				.inversion = false,
 			};
 
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0x60;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
drivers/scsi/qedi/qedi_main.c +1 -1
diff -u -p a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
@@ -2460,7 +2460,7 @@ static int __qedi_probe(struct pci_dev *
 	sp_params.drv_minor = QEDI_DRIVER_MINOR_VER;
 	sp_params.drv_rev = QEDI_DRIVER_REV_VER;
 	sp_params.drv_eng = QEDI_DRIVER_ENG_VER;
-	strlcpy(sp_params.name, "qedi iSCSI", QED_DRV_VER_STR_SIZE);
+	stracpy(sp_params.name, "qedi iSCSI");
 	rc = qedi_ops->common->slowpath_start(qedi->cdev, &sp_params);
 	if (rc) {
 		QEDI_ERR(&qedi->dbg_ctx, "Cannot start slowpath\n");
drivers/firmware/arm_scmi/perf.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
@@ -174,7 +174,7 @@ scmi_perf_domain_attributes_get(const st
 			dom_info->mult_factor =
 					(dom_info->sustained_freq_khz * 1000) /
 					dom_info->sustained_perf_level;
-		strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
+		stracpy(dom_info->name, attr->name);
 	}
 
 	scmi_xfer_put(handle, t);
drivers/hwmon/emc6w201.c +1 -1
diff -u -p a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
@@ -439,7 +439,7 @@ static int emc6w201_detect(struct i2c_cl
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "emc6w201", I2C_NAME_SIZE);
+	stracpy(info->type, "emc6w201");
 
 	return 0;
 }
drivers/clk/tegra/clk-bpmp.c +1 -1
diff -u -p a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
@@ -344,7 +344,7 @@ static int tegra_bpmp_clk_get_info(struc
 	if (err < 0)
 		return err;
 
-	strlcpy(info->name, response.name, MRQ_CLK_NAME_MAXLEN);
+	stracpy(info->name, response.name);
 	info->num_parents = response.num_parents;
 
 	for (i = 0; i < info->num_parents; i++)
drivers/hwmon/emc2103.c +1 -1
diff -u -p a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c
@@ -643,7 +643,7 @@ emc2103_detect(struct i2c_client *new_cl
 	if ((product != 0x24) && (product != 0x26))
 		return -ENODEV;
 
-	strlcpy(info->type, "emc2103", I2C_NAME_SIZE);
+	stracpy(info->type, "emc2103");
 
 	return 0;
 }
drivers/hwmon/w83792d.c +1 -1
diff -u -p a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
@@ -1361,7 +1361,7 @@ w83792d_detect(struct i2c_client *client
 	if (val1 != 0x7a || val2 != 0x5c)
 		return -ENODEV;
 
-	strlcpy(info->type, "w83792d", I2C_NAME_SIZE);
+	stracpy(info->type, "w83792d");
 
 	return 0;
 }
drivers/media/pci/cx18/cx18-i2c.c +1 -1
diff -u -p a/drivers/media/pci/cx18/cx18-i2c.c b/drivers/media/pci/cx18/cx18-i2c.c
@@ -74,7 +74,7 @@ static int cx18_i2c_new_ir(struct cx18 *
 	unsigned short addr_list[2] = { addr, I2C_CLIENT_END };
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, type, I2C_NAME_SIZE);
+	stracpy(info.type, type);
 
 	/* Our default information for ir-kbd-i2c.c to use */
 	switch (hw) {
drivers/crypto/chelsio/chtls/chtls_main.c +1 -1
diff -u -p a/drivers/crypto/chelsio/chtls/chtls_main.c b/drivers/crypto/chelsio/chtls/chtls_main.c
@@ -185,7 +185,7 @@ static void chtls_register_dev(struct ch
 {
 	struct tls_device *tlsdev = &cdev->tlsdev;
 
-	strlcpy(tlsdev->name, "chtls", TLS_DEVICE_NAME_MAX);
+	stracpy(tlsdev->name, "chtls");
 	strlcat(tlsdev->name, cdev->lldi->ports[0]->name,
 		TLS_DEVICE_NAME_MAX);
 	tlsdev->feature = chtls_inline_feature;
drivers/misc/ics932s401.c +1 -1
diff -u -p a/drivers/misc/ics932s401.c b/drivers/misc/ics932s401.c
@@ -424,7 +424,7 @@ static int ics932s401_detect(struct i2c_
 	if (revision != ICS932S401_REV)
 		dev_info(&adapter->dev, "Unknown revision %d\n", revision);
 
-	strlcpy(info->type, "ics932s401", I2C_NAME_SIZE);
+	stracpy(info->type, "ics932s401");
 
 	return 0;
 }
fs/gfs2/ops_fstype.c +5 -5
diff -u -p a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
@@ -372,8 +372,8 @@ static int init_names(struct gfs2_sbd *s
 	if (!table[0])
 		table = sdp->sd_vfs->s_id;
 
-	strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
-	strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
+	stracpy(sdp->sd_proto_name, proto);
+	stracpy(sdp->sd_table_name, table);
 
 	table = sdp->sd_table_name;
 	while ((table = strchr(table, '/')))
@@ -1346,13 +1346,13 @@ static int gfs2_parse_param(struct fs_co
 
 	switch (o) {
 	case Opt_lockproto:
-		strlcpy(args->ar_lockproto, param->string, GFS2_LOCKNAME_LEN);
+		stracpy(args->ar_lockproto, param->string);
 		break;
 	case Opt_locktable:
-		strlcpy(args->ar_locktable, param->string, GFS2_LOCKNAME_LEN);
+		stracpy(args->ar_locktable, param->string);
 		break;
 	case Opt_hostdata:
-		strlcpy(args->ar_hostdata, param->string, GFS2_LOCKNAME_LEN);
+		stracpy(args->ar_hostdata, param->string);
 		break;
 	case Opt_spectator:
 		args->ar_spectator = 1;
drivers/hwmon/dme1737.c +1 -1
diff -u -p a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
@@ -2456,7 +2456,7 @@ static int dme1737_i2c_detect(struct i2c
 	dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
 		 verstep == SCH5027_VERSTEP ? "SCH5027" : "DME1737",
 		 client->addr, verstep);
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/media/pci/bt8xx/bttv-input.c +1 -1
diff -u -p a/drivers/media/pci/bt8xx/bttv-input.c b/drivers/media/pci/bt8xx/bttv-input.c
@@ -373,7 +373,7 @@ void init_bttv_i2c_ir(struct bttv *btv)
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	memset(&btv->init_data, 0, sizeof(btv->init_data));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 
 	switch (btv->c.type) {
 	case BTTV_BOARD_PV951:
drivers/media/usb/tm6000/tm6000-i2c.c +1 -1
diff -u -p a/drivers/media/usb/tm6000/tm6000-i2c.c b/drivers/media/usb/tm6000/tm6000-i2c.c
@@ -300,7 +300,7 @@ int tm6000_i2c_register(struct tm6000_co
 		return rc;
 
 	dev->i2c_client.adapter = &dev->i2c_adap;
-	strscpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE);
+	stracpy(dev->i2c_client.name, "tm6000 internal");
 	tm6000_i2c_eeprom(dev);
 
 	return 0;
drivers/hwmon/adt7475.c +1 -1
diff -u -p a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
@@ -1337,7 +1337,7 @@ static int adt7475_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/thmc50.c +1 -1
diff -u -p a/drivers/hwmon/thmc50.c b/drivers/hwmon/thmc50.c
@@ -352,7 +352,7 @@ static int thmc50_detect(struct i2c_clie
 	pr_debug("thmc50: Detected %s (version %x, revision %x)\n",
 		 type_name, (revision >> 4) - 0xc, revision & 0xf);
 
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
drivers/media/dvb-frontends/m88ds3103.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c
@@ -1274,7 +1274,7 @@ struct dvb_frontend *m88ds3103_attach(co
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
+	stracpy(board_info.type, "m88ds3103");
 	board_info.addr = cfg->i2c_addr;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(i2c, &board_info);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +3 -5
diff -u -p a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
@@ -383,13 +383,11 @@ static void brcmf_mp_attach(void)
 	 * if not set then if available use the platform data version. To make
 	 * sure it gets initialized at all, always copy the module param version
 	 */
-	strlcpy(brcmf_mp_global.firmware_path, brcmf_firmware_path,
-		BRCMF_FW_ALTPATH_LEN);
+	stracpy(brcmf_mp_global.firmware_path, brcmf_firmware_path);
 	if ((brcmfmac_pdata) && (brcmfmac_pdata->fw_alternative_path) &&
 	    (brcmf_mp_global.firmware_path[0] == '\0')) {
-		strlcpy(brcmf_mp_global.firmware_path,
-			brcmfmac_pdata->fw_alternative_path,
-			BRCMF_FW_ALTPATH_LEN);
+		stracpy(brcmf_mp_global.firmware_path,
+			brcmfmac_pdata->fw_alternative_path);
 	}
 }
 
drivers/hwmon/lm93.c +1 -1
diff -u -p a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c
@@ -2575,7 +2575,7 @@ static int lm93_detect(struct i2c_client
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	dev_dbg(&adapter->dev, "loading %s at %d, 0x%02x\n",
 		client->name, i2c_adapter_id(client->adapter),
 		client->addr);
drivers/i2c/busses/i2c-i801.c +3 -3
diff -u -p a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
@@ -1134,7 +1134,7 @@ static void dmi_check_onboard_device(u8
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		info.addr = dmi_devices[i].i2c_addr;
-		strlcpy(info.type, dmi_devices[i].i2c_type, I2C_NAME_SIZE);
+		stracpy(info.type, dmi_devices[i].i2c_type);
 		i2c_new_device(adap, &info);
 		break;
 	}
@@ -1279,7 +1279,7 @@ static void register_dell_lis3lv02d_i2c_
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.addr = dell_lis3lv02d_devices[i].i2c_addr;
-	strlcpy(info.type, "lis3lv02d", I2C_NAME_SIZE);
+	stracpy(info.type, "lis3lv02d");
 	i2c_new_device(&priv->adapter, &info);
 }
 
@@ -1295,7 +1295,7 @@ static void i801_probe_optional_slaves(s
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
 		info.addr = apanel_addr;
-		strlcpy(info.type, "fujitsu_apanel", I2C_NAME_SIZE);
+		stracpy(info.type, "fujitsu_apanel");
 		i2c_new_device(&priv->adapter, &info);
 	}
 
drivers/macintosh/therm_windtunnel.c +2 -2
diff -u -p a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
@@ -320,10 +320,10 @@ do_attach( struct i2c_adapter *adapter )
 		struct i2c_board_info info;
 
 		memset(&info, 0, sizeof(struct i2c_board_info));
-		strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE);
+		stracpy(info.type, "therm_ds1775");
 		i2c_new_probed_device(adapter, &info, scan_ds1775, NULL);
 
-		strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE);
+		stracpy(info.type, "therm_adm1030");
 		i2c_new_probed_device(adapter, &info, scan_adm1030, NULL);
 
 		if( x.thermostat && x.fan ) {
drivers/s390/char/hmcdrv_cache.c +1 -2
diff -u -p a/drivers/s390/char/hmcdrv_cache.c b/drivers/s390/char/hmcdrv_cache.c
@@ -154,8 +154,7 @@ static ssize_t hmcdrv_cache_do(const str
 		/* cache some file info (FTP command, file name and file
 		 * size) unconditionally
 		 */
-		strlcpy(hmcdrv_cache_file.fname, ftp->fname,
-			HMCDRV_FTP_FIDENT_MAX);
+		stracpy(hmcdrv_cache_file.fname, ftp->fname);
 		hmcdrv_cache_file.id = ftp->id;
 		pr_debug("caching cmd %d, file size %zu for '%s'\n",
 			 ftp->id, hmcdrv_cache_file.fsize, ftp->fname);
kernel/relay.c +2 -2
diff -u -p a/kernel/relay.c b/kernel/relay.c
@@ -589,7 +589,7 @@ struct rchan *relay_open(const char *bas
 	chan->private_data = private_data;
 	if (base_filename) {
 		chan->has_base_filename = 1;
-		strlcpy(chan->base_filename, base_filename, NAME_MAX);
+		stracpy(chan->base_filename, base_filename);
 	}
 	setup_callbacks(chan, cb);
 	kref_init(&chan->kref);
@@ -660,7 +660,7 @@ int relay_late_setup_files(struct rchan
 	if (!chan || !base_filename)
 		return -EINVAL;
 
-	strlcpy(chan->base_filename, base_filename, NAME_MAX);
+	stracpy(chan->base_filename, base_filename);
 
 	mutex_lock(&relay_channels_mutex);
 	/* Is chan already set up? */
net/netfilter/ipset/ip_set_core.c +1 -1
diff -u -p a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
@@ -917,7 +917,7 @@ static int ip_set_create(struct net *net
 	if (!set)
 		return -ENOMEM;
 	spin_lock_init(&set->lock);
-	strlcpy(set->name, name, IPSET_MAXNAMELEN);
+	stracpy(set->name, name);
 	set->family = family;
 	set->revision = revision;
 
drivers/firmware/arm_scmi/clock.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
@@ -111,7 +111,7 @@ static int scmi_clock_attributes_get(con
 
 	ret = scmi_do_xfer(handle, t);
 	if (!ret)
-		strlcpy(clk->name, attr->name, SCMI_MAX_STR_SIZE);
+		stracpy(clk->name, attr->name);
 	else
 		clk->name[0] = '\0';
 
drivers/hwmon/lm75.c +1 -1
diff -u -p a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
@@ -607,7 +607,7 @@ static int lm75_detect(struct i2c_client
 			return -ENODEV;
 	}
 
-	strlcpy(info->type, is_lm75a ? "lm75a" : "lm75", I2C_NAME_SIZE);
+	stracpy(info->type, is_lm75a ? "lm75a" : "lm75");
 
 	return 0;
 }
drivers/misc/eeprom/eeprom.c +1 -1
diff -u -p a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
@@ -136,7 +136,7 @@ static int eeprom_detect(struct i2c_clie
 	 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
 		return -ENODEV;
 
-	strlcpy(info->type, "eeprom", I2C_NAME_SIZE);
+	stracpy(info->type, "eeprom");
 
 	return 0;
 }
drivers/s390/block/dasd_eer.c +2 -4
diff -u -p a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
@@ -313,8 +313,7 @@ static void dasd_eer_write_standard_trig
 	ktime_get_real_ts64(&ts);
 	header.tv_sec = ts.tv_sec;
 	header.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
-	strlcpy(header.busid, dev_name(&device->cdev->dev),
-		DASD_EER_BUSID_SIZE);
+	stracpy(header.busid, dev_name(&device->cdev->dev));
 
 	spin_lock_irqsave(&bufferlock, flags);
 	list_for_each_entry(eerb, &bufferlist, list) {
@@ -356,8 +355,7 @@ static void dasd_eer_write_snss_trigger(
 	ktime_get_real_ts64(&ts);
 	header.tv_sec = ts.tv_sec;
 	header.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
-	strlcpy(header.busid, dev_name(&device->cdev->dev),
-		DASD_EER_BUSID_SIZE);
+	stracpy(header.busid, dev_name(&device->cdev->dev));
 
 	spin_lock_irqsave(&bufferlock, flags);
 	list_for_each_entry(eerb, &bufferlist, list) {
net/mac80211/iface.c +1 -1
diff -u -p a/net/mac80211/iface.c b/net/mac80211/iface.c
@@ -1745,7 +1745,7 @@ int ieee80211_if_add(struct ieee80211_lo
 		wdev = &sdata->wdev;
 
 		sdata->dev = NULL;
-		strlcpy(sdata->name, name, IFNAMSIZ);
+		stracpy(sdata->name, name);
 		ieee80211_assign_perm_addr(local, wdev->address, type);
 		memcpy(sdata->vif.addr, wdev->address, ETH_ALEN);
 	} else {
drivers/firmware/arm_scmi/power.c +1 -1
diff -u -p a/drivers/firmware/arm_scmi/power.c b/drivers/firmware/arm_scmi/power.c
@@ -106,7 +106,7 @@ scmi_power_domain_attributes_get(const s
 		dom_info->state_set_notify = SUPPORTS_STATE_SET_NOTIFY(flags);
 		dom_info->state_set_async = SUPPORTS_STATE_SET_ASYNC(flags);
 		dom_info->state_set_sync = SUPPORTS_STATE_SET_SYNC(flags);
-		strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
+		stracpy(dom_info->name, attr->name);
 	}
 
 	scmi_xfer_put(handle, t);
drivers/hwmon/adm1031.c +1 -1
diff -u -p a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
@@ -986,7 +986,7 @@ static int adm1031_detect(struct i2c_cli
 		return -ENODEV;
 	name = (id == 0x30) ? "adm1030" : "adm1031";
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/stts751.c +1 -1
diff -u -p a/drivers/hwmon/stts751.c b/drivers/hwmon/stts751.c
@@ -692,7 +692,7 @@ static int stts751_detect(struct i2c_cli
 	}
 	dev_dbg(&new_client->dev, "Chip %s detected", name);
 
-	strlcpy(info->type, stts751_id[0].name, I2C_NAME_SIZE);
+	stracpy(info->type, stts751_id[0].name);
 	return 0;
 }
 
drivers/infiniband/core/device.c +2 -2
diff -u -p a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
@@ -429,7 +429,7 @@ int ib_device_rename(struct ib_device *i
 		return ret;
 	}
 
-	strlcpy(ibdev->name, name, IB_DEVICE_NAME_MAX);
+	stracpy(ibdev->name, name);
 	ret = rename_compat_devs(ibdev);
 
 	downgrade_write(&devices_rwsem);
@@ -1142,7 +1142,7 @@ static int assign_name(struct ib_device
 		ret = -ENFILE;
 		goto out;
 	}
-	strlcpy(device->name, dev_name(&device->dev), IB_DEVICE_NAME_MAX);
+	stracpy(device->name, dev_name(&device->dev));
 
 	ret = xa_alloc_cyclic(&devices, &device->index, device, xa_limit_31b,
 			&last_id, GFP_KERNEL);
drivers/mfd/htc-i2cpld.c +1 -1
diff -u -p a/drivers/mfd/htc-i2cpld.c b/drivers/mfd/htc-i2cpld.c
@@ -351,7 +351,7 @@ static int htcpld_register_chip_i2c(
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.addr = plat_chip_data->addr;
-	strlcpy(info.type, "htcpld-chip", I2C_NAME_SIZE);
+	stracpy(info.type, "htcpld-chip");
 	info.platform_data = chip;
 
 	/* Add the I2C device.  This calls the probe() function. */
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +1 -2
diff -u -p a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -3364,8 +3364,7 @@ static void bnx2x_drv_info_ether_stat(st
 		&bp->sp_objs->mac_obj;
 	int i;
 
-	strlcpy(ether_stat->version, DRV_MODULE_VERSION,
-		ETH_STAT_INFO_VERSION_LEN);
+	stracpy(ether_stat->version, DRV_MODULE_VERSION);
 
 	/* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
 	 * mac_local field in ether_stat struct. The base address is offset by 2
tools/perf/util/machine.c +3 -3
diff -u -p a/tools/perf/util/machine.c b/tools/perf/util/machine.c
@@ -988,7 +988,7 @@ int machine__create_extra_kernel_map(str
 	kmap = map__kmap(map);
 
 	kmap->kmaps = &machine->kmaps;
-	strlcpy(kmap->name, xm->name, KMAP_NAME_LEN);
+	stracpy(kmap->name, xm->name);
 
 	map_groups__insert(&machine->kmaps, map);
 
@@ -1078,7 +1078,7 @@ int machine__map_x86_64_entry_trampoline
 			.pgoff = pgoff,
 		};
 
-		strlcpy(xm.name, ENTRY_TRAMPOLINE_NAME, KMAP_NAME_LEN);
+		stracpy(xm.name, ENTRY_TRAMPOLINE_NAME);
 
 		if (machine__create_extra_kernel_map(machine, kernel, &xm) < 0)
 			return -1;
@@ -1542,7 +1542,7 @@ static int machine__process_extra_kernel
 	if (kernel == NULL)
 		return -1;
 
-	strlcpy(xm.name, event->mmap.filename, KMAP_NAME_LEN);
+	stracpy(xm.name, event->mmap.filename);
 
 	return machine__create_extra_kernel_map(machine, kernel, &xm);
 }
drivers/hwmon/lm95241.c +1 -1
diff -u -p a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
@@ -389,7 +389,7 @@ static int lm95241_detect(struct i2c_cli
 	}
 
 	/* Fill the i2c board info */
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	return 0;
 }
 
drivers/media/i2c/saa7127.c +2 -2
diff -u -p a/drivers/media/i2c/saa7127.c b/drivers/media/i2c/saa7127.c
@@ -752,10 +752,10 @@ static int saa7127_probe(struct i2c_clie
 			saa7127_write(sd, SAA7129_REG_FADE_KEY_COL2,
 					read_result);
 			state->ident = SAA7129;
-			strscpy(client->name, "saa7129", I2C_NAME_SIZE);
+			stracpy(client->name, "saa7129");
 		} else {
 			state->ident = SAA7127;
-			strscpy(client->name, "saa7127", I2C_NAME_SIZE);
+			stracpy(client->name, "saa7127");
 		}
 	}
 
sound/aoa/codecs/tas.c +1 -1
diff -u -p a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
@@ -894,7 +894,7 @@ static int tas_i2c_probe(struct i2c_clie
 	/* seems that half is a saner default */
 	tas->drc_range = TAS3004_DRC_MAX / 2;
 
-	strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN);
+	stracpy(tas->codec.name, "tas");
 	tas->codec.owner = THIS_MODULE;
 	tas->codec.init = tas_init_codec;
 	tas->codec.exit = tas_exit_codec;
drivers/hwmon/lm95245.c +1 -1
diff -u -p a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c
@@ -461,7 +461,7 @@ static int lm95245_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 	return 0;
 }
 
drivers/hwmon/gl520sm.c +1 -1
diff -u -p a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
@@ -811,7 +811,7 @@ static int gl520_detect(struct i2c_clien
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "gl520sm", I2C_NAME_SIZE);
+	stracpy(info->type, "gl520sm");
 
 	return 0;
 }
drivers/media/pci/saa7164/saa7164-dvb.c +5 -5
diff -u -p a/drivers/media/pci/saa7164/saa7164-dvb.c b/drivers/media/pci/saa7164/saa7164-dvb.c
@@ -110,7 +110,7 @@ static int si2157_attach(struct saa7164_
 
 	memset(&bi, 0, sizeof(bi));
 
-	strscpy(bi.type, "si2157", I2C_NAME_SIZE);
+	stracpy(bi.type, "si2157");
 	bi.platform_data = cfg;
 	bi.addr = addr8bit >> 1;
 
@@ -633,7 +633,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2168_config.fe = &port->dvb.frontend;
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0xc8 >> 1;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -653,7 +653,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2157_config.if_port = 1;
 			si2157_config.fe = port->dvb.frontend;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0xc0 >> 1;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
@@ -678,7 +678,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2168_config.fe = &port->dvb.frontend;
 			si2168_config.ts_mode = SI2168_TS_SERIAL;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2168", I2C_NAME_SIZE);
+			stracpy(info.type, "si2168");
 			info.addr = 0xcc >> 1;
 			info.platform_data = &si2168_config;
 			request_module(info.type);
@@ -698,7 +698,7 @@ int saa7164_dvb_register(struct saa7164_
 			si2157_config.fe = port->dvb.frontend;
 			si2157_config.if_port = 1;
 			memset(&info, 0, sizeof(struct i2c_board_info));
-			strscpy(info.type, "si2157", I2C_NAME_SIZE);
+			stracpy(info.type, "si2157");
 			info.addr = 0xc0 >> 1;
 			info.platform_data = &si2157_config;
 			request_module(info.type);
drivers/media/usb/dvb-usb/dw2102.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
@@ -1586,7 +1586,7 @@ static int tt_s2_4600_frontend_attach(st
 	m88ds3103_pdata.lnb_hv_pol = 1;
 	m88ds3103_pdata.lnb_en_pol = 0;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
+	stracpy(board_info.type, "m88ds3103");
 	board_info.addr = 0x68;
 	board_info.platform_data = &m88ds3103_pdata;
 	request_module("m88ds3103");
@@ -1605,7 +1605,7 @@ static int tt_s2_4600_frontend_attach(st
 	/* attach tuner */
 	ts2020_config.fe = adap->fe_adap[0].fe;
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "ts2022", I2C_NAME_SIZE);
+	stracpy(board_info.type, "ts2022");
 	board_info.addr = 0x60;
 	board_info.platform_data = &ts2020_config;
 	request_module("ts2020");
drivers/net/ethernet/realtek/r8169_firmware.c +2 -2
diff -u -p a/drivers/net/ethernet/realtek/r8169_firmware.c b/drivers/net/ethernet/realtek/r8169_firmware.c
@@ -68,7 +68,7 @@ static bool rtl_fw_format_ok(struct rtl_
 		if (size > (fw->size - start) / FW_OPCODE_SIZE)
 			return false;
 
-		strscpy(rtl_fw->version, fw_info->version, RTL_VER_SIZE);
+		stracpy(rtl_fw->version, fw_info->version);
 
 		pa->code = (__le32 *)(fw->data + start);
 		pa->size = size;
@@ -76,7 +76,7 @@ static bool rtl_fw_format_ok(struct rtl_
 		if (fw->size % FW_OPCODE_SIZE)
 			return false;
 
-		strscpy(rtl_fw->version, rtl_fw->fw_name, RTL_VER_SIZE);
+		stracpy(rtl_fw->version, rtl_fw->fw_name);
 
 		pa->code = (__le32 *)fw->data;
 		pa->size = fw->size / FW_OPCODE_SIZE;
drivers/platform/x86/intel_cht_int33fe.c +3 -3
diff -u -p a/drivers/platform/x86/intel_cht_int33fe.c b/drivers/platform/x86/intel_cht_int33fe.c
@@ -285,7 +285,7 @@ cht_int33fe_register_max17047(struct dev
 	}
 
 	memset(&board_info, 0, sizeof(board_info));
-	strlcpy(board_info.type, "max17047", I2C_NAME_SIZE);
+	stracpy(board_info.type, "max17047");
 	board_info.dev_name = "max17047";
 	board_info.fwnode = fwnode;
 	data->max17047 = i2c_acpi_new_device(dev, 1, &board_info);
@@ -374,7 +374,7 @@ static int cht_int33fe_probe(struct plat
 	}
 
 	memset(&board_info, 0, sizeof(board_info));
-	strlcpy(board_info.type, "typec_fusb302", I2C_NAME_SIZE);
+	stracpy(board_info.type, "typec_fusb302");
 	board_info.dev_name = "fusb302";
 	board_info.fwnode = fwnode;
 	board_info.irq = fusb302_irq;
@@ -394,7 +394,7 @@ static int cht_int33fe_probe(struct plat
 	memset(&board_info, 0, sizeof(board_info));
 	board_info.dev_name = "pi3usb30532";
 	board_info.fwnode = fwnode;
-	strlcpy(board_info.type, "pi3usb30532", I2C_NAME_SIZE);
+	stracpy(board_info.type, "pi3usb30532");
 
 	data->pi3usb30532 = i2c_acpi_new_device(dev, 3, &board_info);
 	if (IS_ERR(data->pi3usb30532)) {
net/core/netpoll.c +1 -1
diff -u -p a/net/core/netpoll.c b/net/core/netpoll.c
@@ -588,7 +588,7 @@ int __netpoll_setup(struct netpoll *np,
 	int err;
 
 	np->dev = ndev;
-	strlcpy(np->dev_name, ndev->name, IFNAMSIZ);
+	stracpy(np->dev_name, ndev->name);
 
 	if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
 		np_err(np, "%s doesn't support polling, aborting\n",
drivers/hwmon/lm92.c +1 -1
diff -u -p a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
@@ -287,7 +287,7 @@ static int lm92_detect(struct i2c_client
 	else
 		return -ENODEV;
 
-	strlcpy(info->type, "lm92", I2C_NAME_SIZE);
+	stracpy(info->type, "lm92");
 
 	return 0;
 }
drivers/media/dvb-frontends/ts2020.c +1 -1
diff -u -p a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
@@ -516,7 +516,7 @@ struct dvb_frontend *ts2020_attach(struc
 	pdata.attach_in_use = true;
 
 	memset(&board_info, 0, sizeof(board_info));
-	strscpy(board_info.type, "ts2020", I2C_NAME_SIZE);
+	stracpy(board_info.type, "ts2020");
 	board_info.addr = config->tuner_address;
 	board_info.platform_data = &pdata;
 	client = i2c_new_device(i2c, &board_info);
drivers/soc/qcom/apr.c +1 -1
diff -u -p a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
@@ -273,7 +273,7 @@ static int apr_add_device(struct device
 	if (np)
 		snprintf(adev->name, APR_NAME_SIZE, "%pOFn", np);
 	else
-		strscpy(adev->name, id->name, APR_NAME_SIZE);
+		stracpy(adev->name, id->name);
 
 	dev_set_name(&adev->dev, "aprsvc:%s:%x:%x", adev->name,
 		     id->domain_id, id->svc_id);
kernel/kallsyms.c +1 -1
diff -u -p a/kernel/kallsyms.c b/kernel/kallsyms.c
@@ -495,7 +495,7 @@ static int get_ksymbol_ftrace_mod(struct
 
 static int get_ksymbol_bpf(struct kallsym_iter *iter)
 {
-	strlcpy(iter->module_name, "bpf", MODULE_NAME_LEN);
+	stracpy(iter->module_name, "bpf");
 	iter->exported = 0;
 	return bpf_get_kallsym(iter->pos - iter->pos_ftrace_mod_end,
 			       &iter->value, &iter->type,
drivers/hwmon/adm1025.c +1 -1
diff -u -p a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
@@ -470,7 +470,7 @@ static int adm1025_detect(struct i2c_cli
 	else
 		return -ENODEV;
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/hwmon/w83781d.c +1 -1
diff -u -p a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
@@ -1171,7 +1171,7 @@ w83781d_detect(struct i2c_client *client
 	if (isa)
 		mutex_unlock(&isa->update_lock);
 
-	strlcpy(info->type, client_name, I2C_NAME_SIZE);
+	stracpy(info->type, client_name);
 
 	return 0;
 
drivers/net/ethernet/qlogic/qede/qede_main.c +1 -1
diff -u -p a/drivers/net/ethernet/qlogic/qede/qede_main.c b/drivers/net/ethernet/qlogic/qede/qede_main.c
@@ -1094,7 +1094,7 @@ static int __qede_probe(struct pci_dev *
 	sp_params.drv_minor = QEDE_MINOR_VERSION;
 	sp_params.drv_rev = QEDE_REVISION_VERSION;
 	sp_params.drv_eng = QEDE_ENGINEERING_VERSION;
-	strlcpy(sp_params.name, "qede LAN", QED_DRV_VER_STR_SIZE);
+	stracpy(sp_params.name, "qede LAN");
 	rc = qed_ops->common->slowpath_start(cdev, &sp_params);
 	if (rc) {
 		pr_notice("Cannot start slowpath\n");
net/l2tp/l2tp_eth.c +1 -1
diff -u -p a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
@@ -328,7 +328,7 @@ static int l2tp_eth_create(struct net *n
 		return rc;
 	}
 
-	strlcpy(session->ifname, dev->name, IFNAMSIZ);
+	stracpy(session->ifname, dev->name);
 	rcu_assign_pointer(spriv->dev, dev);
 
 	rtnl_unlock();
drivers/hwmon/lm80.c +1 -1
diff -u -p a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
@@ -586,7 +586,7 @@ static int lm80_detect(struct i2c_client
 		name = "lm80";
 	}
 
-	strlcpy(info->type, name, I2C_NAME_SIZE);
+	stracpy(info->type, name);
 
 	return 0;
 }
drivers/thermal/thermal_hwmon.c +1 -1
diff -u -p a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c
@@ -141,7 +141,7 @@ int thermal_add_hwmon_sysfs(struct therm
 		return -ENOMEM;
 
 	INIT_LIST_HEAD(&hwmon->tz_list);
-	strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
+	stracpy(hwmon->type, tz->type);
 	strreplace(hwmon->type, '-', '_');
 	hwmon->device = hwmon_device_register_with_info(&tz->device, hwmon->type,
 							hwmon, NULL, NULL);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
diff -u -p a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -4850,7 +4850,7 @@ amdgpu_dm_create_common_mode(struct drm_
 	mode->hdisplay = hdisplay;
 	mode->vdisplay = vdisplay;
 	mode->type &= ~DRM_MODE_TYPE_PREFERRED;
-	strscpy(mode->name, name, DRM_DISPLAY_MODE_LEN);
+	stracpy(mode->name, name);
 
 	return mode;
 
include/rdma/rdma_vt.h +1 -1
diff -u -p a/include/rdma/rdma_vt.h b/include/rdma/rdma_vt.h
@@ -486,7 +486,7 @@ static inline void rvt_set_ibdev_name(st
 	 * to work by setting the name manually here.
 	 */
 	dev_set_name(&rdi->ibdev.dev, fmt, name, unit);
-	strlcpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev), IB_DEVICE_NAME_MAX);
+	stracpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev));
 }
 
 /**
drivers/media/usb/dvb-usb/cxusb.c +2 -2
diff -u -p a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
@@ -1406,7 +1406,7 @@ static int cxusb_mygica_t230_frontend_at
 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
 	si2168_config.ts_clock_inv = 1;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "si2168", I2C_NAME_SIZE);
+	stracpy(info.type, "si2168");
 	info.addr = 0x64;
 	info.platform_data = &si2168_config;
 	request_module(info.type);
@@ -1426,7 +1426,7 @@ static int cxusb_mygica_t230_frontend_at
 	si2157_config.fe = adap->fe_adap[0].fe;
 	si2157_config.if_port = 1;
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "si2157", I2C_NAME_SIZE);
+	stracpy(info.type, "si2157");
 	info.addr = 0x60;
 	info.platform_data = &si2157_config;
 	request_module(info.type);
drivers/scsi/bfa/bfa_fcs.c +2 -4
diff -u -p a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
@@ -761,8 +761,7 @@ bfa_fcs_fabric_psymb_init(struct bfa_fcs
 	bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
 
 	/* Model name/number */
-	strlcpy(port_cfg->sym_name.symname, model,
-		BFA_SYMNAME_MAXLEN);
+	stracpy(port_cfg->sym_name.symname, model);
 	strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
 		BFA_SYMNAME_MAXLEN);
 
@@ -822,8 +821,7 @@ bfa_fcs_fabric_nsymb_init(struct bfa_fcs
 	bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
 
 	/* Model name/number */
-	strlcpy(port_cfg->node_sym_name.symname, model,
-		BFA_SYMNAME_MAXLEN);
+	stracpy(port_cfg->node_sym_name.symname, model);
 	strlcat(port_cfg->node_sym_name.symname,
 			BFA_FCS_PORT_SYMBNAME_SEPARATOR,
 			BFA_SYMNAME_MAXLEN);
drivers/hwmon/amc6821.c +1 -1
diff -u -p a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
@@ -809,7 +809,7 @@ static int amc6821_detect(
 	}
 
 	dev_info(&adapter->dev, "amc6821: chip found at 0x%02x.\n", address);
-	strlcpy(info->type, "amc6821", I2C_NAME_SIZE);
+	stracpy(info->type, "amc6821");
 
 	return 0;
 }
drivers/hwmon/w83791d.c +1 -1
diff -u -p a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
@@ -1349,7 +1349,7 @@ static int w83791d_detect(struct i2c_cli
 	if (val1 != 0x71 || val2 != 0x5c)
 		return -ENODEV;
 
-	strlcpy(info->type, "w83791d", I2C_NAME_SIZE);
+	stracpy(info->type, "w83791d");
 
 	return 0;
 }
drivers/s390/char/tape_class.c +2 -2
diff -u -p a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
@@ -54,10 +54,10 @@ struct tape_class_device *register_tape_
 	if (!tcd)
 		return ERR_PTR(-ENOMEM);
 
-	strlcpy(tcd->device_name, device_name, TAPECLASS_NAME_LEN);
+	stracpy(tcd->device_name, device_name);
 	for (s = strchr(tcd->device_name, '/'); s; s = strchr(s, '/'))
 		*s = '!';
-	strlcpy(tcd->mode_name, mode_name, TAPECLASS_NAME_LEN);
+	stracpy(tcd->mode_name, mode_name);
 	for (s = strchr(tcd->mode_name, '/'); s; s = strchr(s, '/'))
 		*s = '!';
 
drivers/hwmon/adm1029.c +1 -1
diff -u -p a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c
@@ -329,7 +329,7 @@ static int adm1029_detect(struct i2c_cli
 		return -ENODEV;
 	}
 
-	strlcpy(info->type, "adm1029", I2C_NAME_SIZE);
+	stracpy(info->type, "adm1029");
 
 	return 0;
 }
drivers/media/pci/smipcie/smipcie-main.c +4 -4
diff -u -p a/drivers/media/pci/smipcie/smipcie-main.c b/drivers/media/pci/smipcie/smipcie-main.c
@@ -540,7 +540,7 @@ static int smi_dvbsky_m88ds3103_fe_attac
 	}
 	/* attach tuner */
 	ts2020_config.fe = port->fe;
-	strscpy(tuner_info.type, "ts2020", I2C_NAME_SIZE);
+	stracpy(tuner_info.type, "ts2020");
 	tuner_info.addr = 0x60;
 	tuner_info.platform_data = &ts2020_config;
 	tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info);
@@ -596,7 +596,7 @@ static int smi_dvbsky_m88rs6000_fe_attac
 	}
 	/* attach tuner */
 	m88rs6000t_config.fe = port->fe;
-	strscpy(tuner_info.type, "m88rs6000t", I2C_NAME_SIZE);
+	stracpy(tuner_info.type, "m88rs6000t");
 	tuner_info.addr = 0x21;
 	tuner_info.platform_data = &m88rs6000t_config;
 	tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info);
@@ -638,7 +638,7 @@ static int smi_dvbsky_sit2_fe_attach(str
 	si2168_config.ts_mode = SI2168_TS_PARALLEL;
 
 	memset(&client_info, 0, sizeof(struct i2c_board_info));
-	strscpy(client_info.type, "si2168", I2C_NAME_SIZE);
+	stracpy(client_info.type, "si2168");
 	client_info.addr = 0x64;
 	client_info.platform_data = &si2168_config;
 
@@ -655,7 +655,7 @@ static int smi_dvbsky_sit2_fe_attach(str
 	si2157_config.if_port = 1;
 
 	memset(&client_info, 0, sizeof(struct i2c_board_info));
-	strscpy(client_info.type, "si2157", I2C_NAME_SIZE);
+	stracpy(client_info.type, "si2157");
 	client_info.addr = 0x60;
 	client_info.platform_data = &si2157_config;
 
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +2 -2
diff -u -p a/drivers/net/ethernet/marvell/octeontx2/af/rvu.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu.c
@@ -2367,8 +2367,8 @@ static void rvu_update_module_params(str
 {
 	const char *default_pfl_name = "default";
 
-	strscpy(rvu->mkex_pfl_name,
-		mkex_profile ? mkex_profile : default_pfl_name, MKEX_NAME_LEN);
+	stracpy(rvu->mkex_pfl_name,
+		mkex_profile ? mkex_profile : default_pfl_name);
 }
 
 static int rvu_probe(struct pci_dev *pdev, const struct pci_device_id *id)
drivers/platform/x86/i2c-multi-instantiate.c +1 -1
diff -u -p a/drivers/platform/x86/i2c-multi-instantiate.c b/drivers/platform/x86/i2c-multi-instantiate.c
@@ -91,7 +91,7 @@ static int i2c_multi_inst_probe(struct p
 
 	for (i = 0; i < multi->num_clients && inst_data[i].type; i++) {
 		memset(&board_info, 0, sizeof(board_info));
-		strlcpy(board_info.type, inst_data[i].type, I2C_NAME_SIZE);
+		stracpy(board_info.type, inst_data[i].type);
 		snprintf(name, sizeof(name), "%s-%s.%d", match->id,
 			 inst_data[i].type, i);
 		board_info.dev_name = name;
drivers/staging/greybus/audio_module.c +1 -1
diff -u -p a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c
@@ -341,7 +341,7 @@ static int gb_audio_probe(struct gb_bund
 	/* inform above layer for uevent */
 	dev_dbg(dev, "Inform set_event:%d to above layer\n", 1);
 	/* prepare for the audio manager */
-	strlcpy(desc.name, gbmodule->name, GB_AUDIO_MANAGER_MODULE_NAME_LEN);
+	stracpy(desc.name, gbmodule->name);
 	desc.vid = 2; /* todo */
 	desc.pid = 3; /* todo */
 	desc.intf_id = gbmodule->dev_id;
drivers/hwmon/fschmd.c +1 -1
diff -u -p a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
@@ -1075,7 +1075,7 @@ static int fschmd_detect(struct i2c_clie
 	else
 		return -ENODEV;
 
-	strlcpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE);
+	stracpy(info->type, fschmd_id[kind].name);
 
 	return 0;
 }
fs/orangefs/orangefs-utils.c +2 -3
diff -u -p a/fs/orangefs/orangefs-utils.c b/fs/orangefs/orangefs-utils.c
@@ -335,9 +335,8 @@ again2:
 		if (flags & ORANGEFS_GETATTR_NEW) {
 			inode->i_size = (loff_t)strlen(new_op->
 			    downcall.resp.getattr.link_target);
-			ret = strscpy(orangefs_inode->link_target,
-			    new_op->downcall.resp.getattr.link_target,
-			    ORANGEFS_NAME_MAX);
+			ret = stracpy(orangefs_inode->link_target,
+			    new_op->downcall.resp.getattr.link_target);
 			if (ret == -E2BIG) {
 				ret = -EIO;
 				goto out_unlock;
drivers/hwmon/adm1021.c +1 -1
diff -u -p a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
@@ -411,7 +411,7 @@ static int adm1021_detect(struct i2c_cli
 
 	pr_debug("Detected chip %s at adapter %d, address 0x%02x.\n",
 		 type_name, i2c_adapter_id(adapter), client->addr);
-	strlcpy(info->type, type_name, I2C_NAME_SIZE);
+	stracpy(info->type, type_name);
 
 	return 0;
 }
drivers/hwmon/max6642.c +1 -1
diff -u -p a/drivers/hwmon/max6642.c b/drivers/hwmon/max6642.c
@@ -148,7 +148,7 @@ static int max6642_detect(struct i2c_cli
 	if ((reg_status & 0x2b) != 0x00)
 		return -ENODEV;
 
-	strlcpy(info->type, "max6642", I2C_NAME_SIZE);
+	stracpy(info->type, "max6642");
 
 	return 0;
 }
drivers/media/pci/ivtv/ivtv-i2c.c +2 -2
diff -u -p a/drivers/media/pci/ivtv/ivtv-i2c.c b/drivers/media/pci/ivtv/ivtv-i2c.c
@@ -206,7 +206,7 @@ static int ivtv_i2c_new_ir(struct ivtv *
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	info.platform_data = init_data;
-	strscpy(info.type, type, I2C_NAME_SIZE);
+	stracpy(info.type, type);
 
 	return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
 	       -1 : 0;
@@ -234,7 +234,7 @@ struct i2c_client *ivtv_i2c_new_ir_legac
 	};
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
-	strscpy(info.type, "ir_video", I2C_NAME_SIZE);
+	stracpy(info.type, "ir_video");
 	return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL);
 }
 
drivers/usb/wusbcore/cbaf.c +1 -1
diff -u -p a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
@@ -289,7 +289,7 @@ static int cbaf_cdid_get(struct cbaf *cb
 		return -ENOENT;
 	}
 
-	strlcpy(cbaf->device_name, di->DeviceFriendlyName, CBA_NAME_LEN);
+	stracpy(cbaf->device_name, di->DeviceFriendlyName);
 	cbaf->cdid = di->CDID;
 	cbaf->device_band_groups = le16_to_cpu(di->BandGroups);
 
#35 lore raw

Re: [1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 2 lines

The rule now properly checks that the third argument is the size of the first argument. This made a small reduction in the number of results.

Thanks for your SmPL script adjustments.
Will deviations from this restriction become more interesting?

Quoted 1 line

\(strscpy\|strlcpy\)(e1.f, e2, i2)@p

Would you like to take the function “strscpy_pad” also into account for source code transformations with the macro “stracpy_pad”?

Regards,
Markus

#36 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

In reply to Joe Perches

I see that stracpy is now in linux-next. Would it be reasonable to send patches adding uses now? Are there any rules for adding calls to stracpy_pad?

julia

#37 lore raw

Re: [Fwd: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms]

Quoted 2 lines · Julia Lawall

I see that stracpy is now in linux-next. Would it be reasonable to send patches adding uses now?

My preference would be to have:

o A provably correct script If a small subset of possible conversions are skipped, that's fine.
o As piecemeal patches cause a lot of churn, work for individual maintainers, and also are not universally applied, have that script run kernel-wide after an rc1 and applied all-at-once.

Reviewed-by on v1 1/2
#38 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

In reply to Joe Perches
Quoted 9 lines · Joe Perches

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

Quoted 6 lines

These mechanisms verify that the to argument is an array of char or other compatible types like u8 or unsigned char.

A BUILD_BUG is emitted when the type of to is not compatible.

I think Rasmus's suggestion would make sense:

	BUILD_BUG_ON(!__same_type(typeof(to), char[]))

Either way, I think it should be fine:

-Kees

Quoted 59 lines
---
 include/linux/string.h | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
include/linux/string.h +41 -0
index 4deb11f7976b..f80b0973f0e5 100644
@@ -35,6 +35,47 @@ ssize_t strscpy(char *, const char *, size_t);
 /* Wraps calls to strscpy()/memset(), no arch specific code required */
 ssize_t strscpy_pad(char *dest, const char *src, size_t count);
 
+/**
+ * stracpy - Copy a C-string into an array of char
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination.
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.
+ */
+#define stracpy(to, from)					\
+({								\
+	size_t size = ARRAY_SIZE(to);				\
+	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
+								\
+	strscpy(to, from, size);				\
+})
+
+/**
+ * stracpy_pad - Copy a C-string into an array of char with %NUL padding
+ * @to: Where to copy the string, must be an array of char and not a pointer
+ * @from: String to copy, may be a pointer or const char array
+ *
+ * Helper for strscpy_pad.
+ * Copies a maximum of sizeof(@to) bytes of @from with %NUL termination
+ * and zero-pads the remaining size of @to
+ *
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if @to is a zero size array.
+ */
+#define stracpy_pad(to, from)					\
+({								\
+	size_t size = ARRAY_SIZE(to);				\
+	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
+								\
+	strscpy_pad(to, from, size);				\
+})
+
 #ifndef __HAVE_ARCH_STRCAT
 extern char * strcat(char *, const char *);
 #endif
Signature · 1 line
2.15.0
Signature · 1 line
Kees Cook
#39 lore raw

Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms

Quoted 13 lines · Kees Cook
Quoted 12 lines · Joe Perches

Several uses of strlcpy and strscpy have had defects because the last argument of each function is misused or typoed.

Add macro mechanisms to avoid this defect.

stracpy (copy a string to a string array) must have a string array as the first argument (to) and uses sizeof(to) as the size.

These mechanisms verify that the to argument is an array of char or other compatible types like u8 or unsigned char.

Quoted 7 lines
Quoted 3 lines

A BUILD_BUG is emitted when the type of to is not compatible.

I think Rasmus's suggestion would make sense:

	BUILD_BUG_ON(!__same_type(typeof(to), char[]))

I think Rasmus had an excellent suggestion.
I liked it and submitted it as V2.

Quoted 1 line

Thanks.

#40 lore raw

PATCH 2/2 kernel-doc: core-api: Include string.h into core-api

In reply to Joe Perches

core-api should show all the various string functions including the newly added stracpy and stracpy_pad.

Miscellanea:

o Update the Returns: value for strscpy
o fix a defect with %NUL)

---
 Documentation/core-api/kernel-api.rst |  3 +++
 include/linux/string.h                |  5 +++--
 lib/string.c                          | 10 ++++++----
 3 files changed, 12 insertions(+), 6 deletions(-)
Documentation/core-api/kernel-api.rst +3 -0
index 08af5caf036d..f77de49b1d51 100644
@@ -42,6 +42,9 @@ String Manipulation
 .. kernel-doc:: lib/string.c
    :export:
 
+.. kernel-doc:: include/linux/string.h
+   :internal:
+
 .. kernel-doc:: mm/util.c
    :functions: kstrdup kstrdup_const kstrndup kmemdup kmemdup_nul memdup_user
                vmemdup_user strndup_user memdup_user_nul
include/linux/string.h +3 -2
index f80b0973f0e5..329188fffc11 100644
@@ -515,8 +515,9 @@ static inline void memcpy_and_pad(void *dest, size_t dest_len,
  * But this can lead to bugs due to typos, or if prefix is a pointer
  * and not a constant. Instead use str_has_prefix().
  *
- * Returns: 0 if @str does not start with @prefix
-         strlen(@prefix) if @str does start with @prefix
+ * Returns:
+ * * strlen(@prefix) if @str starts with @prefix
+ * * 0 if @str does not start with @prefix
  */
 static __always_inline size_t str_has_prefix(const char *str, const char *prefix)
 {
lib/string.c +6 -4
index 461fb620f85f..53582b6dce2a 100644
@@ -173,8 +173,9 @@ EXPORT_SYMBOL(strlcpy);
  * doesn't unnecessarily force the tail of the destination buffer to be
  * zeroed.  If zeroing is desired please use strscpy_pad().
  *
- * Return: The number of characters copied (not including the trailing
- *         %NUL) or -E2BIG if the destination buffer wasn't big enough.
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if count is 0.
  */
 ssize_t strscpy(char *dest, const char *src, size_t count)
 {
@@ -253,8 +254,9 @@ EXPORT_SYMBOL(strscpy);
  * For full explanation of why you may want to consider using the
  * 'strscpy' functions please see the function docstring for strscpy().
  *
- * Return: The number of characters copied (not including the trailing
- *         %NUL) or -E2BIG if the destination buffer wasn't big enough.
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if count is 0.
  */
 ssize_t strscpy_pad(char *dest, const char *src, size_t count)
 {
Signature · 1 line
2.15.0
Reviewed-by on v1 2/2
#41 lore raw

Re: [PATCH 2/2] kernel-doc: core-api: Include string.h into core-api

Quoted 9 lines · Joe Perches

core-api should show all the various string functions including the newly added stracpy and stracpy_pad.

Miscellanea:

o Update the Returns: value for strscpy
o fix a defect with %NUL)

-Kees

Quoted 67 lines
---
 Documentation/core-api/kernel-api.rst |  3 +++
 include/linux/string.h                |  5 +++--
 lib/string.c                          | 10 ++++++----
 3 files changed, 12 insertions(+), 6 deletions(-)
Documentation/core-api/kernel-api.rst +3 -0
index 08af5caf036d..f77de49b1d51 100644
@@ -42,6 +42,9 @@ String Manipulation
 .. kernel-doc:: lib/string.c
    :export:
 
+.. kernel-doc:: include/linux/string.h
+   :internal:
+
 .. kernel-doc:: mm/util.c
    :functions: kstrdup kstrdup_const kstrndup kmemdup kmemdup_nul memdup_user
                vmemdup_user strndup_user memdup_user_nul
include/linux/string.h +3 -2
index f80b0973f0e5..329188fffc11 100644
@@ -515,8 +515,9 @@ static inline void memcpy_and_pad(void *dest, size_t dest_len,
  * But this can lead to bugs due to typos, or if prefix is a pointer
  * and not a constant. Instead use str_has_prefix().
  *
- * Returns: 0 if @str does not start with @prefix
-         strlen(@prefix) if @str does start with @prefix
+ * Returns:
+ * * strlen(@prefix) if @str starts with @prefix
+ * * 0 if @str does not start with @prefix
  */
 static __always_inline size_t str_has_prefix(const char *str, const char *prefix)
 {
lib/string.c +6 -4
index 461fb620f85f..53582b6dce2a 100644
@@ -173,8 +173,9 @@ EXPORT_SYMBOL(strlcpy);
  * doesn't unnecessarily force the tail of the destination buffer to be
  * zeroed.  If zeroing is desired please use strscpy_pad().
  *
- * Return: The number of characters copied (not including the trailing
- *         %NUL) or -E2BIG if the destination buffer wasn't big enough.
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if count is 0.
  */
 ssize_t strscpy(char *dest, const char *src, size_t count)
 {
@@ -253,8 +254,9 @@ EXPORT_SYMBOL(strscpy);
  * For full explanation of why you may want to consider using the
  * 'strscpy' functions please see the function docstring for strscpy().
  *
- * Return: The number of characters copied (not including the trailing
- *         %NUL) or -E2BIG if the destination buffer wasn't big enough.
+ * Returns:
+ * * The number of characters copied (not including the trailing %NUL)
+ * * -E2BIG if count is 0.
  */
 ssize_t strscpy_pad(char *dest, const char *src, size_t count)
 {
Signature · 1 line
2.15.0
Signature · 1 line
Kees Cook