Commit a34eddfe authored by Chris Metcalf's avatar Chris Metcalf Committed by Greg Kroah-Hartman

tile: use global strscpy() rather than private copy

commit 30059d49 upstream.

Now that strscpy() is a standard API, remove the local copy.
Signed-off-by: default avatarChris Metcalf <cmetcalf@ezchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d9110554
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/string.h>
#include <gxio/iorpc_globals.h> #include <gxio/iorpc_globals.h>
#include <gxio/iorpc_mpipe.h> #include <gxio/iorpc_mpipe.h>
...@@ -29,32 +30,6 @@ ...@@ -29,32 +30,6 @@
/* HACK: Avoid pointless "shadow" warnings. */ /* HACK: Avoid pointless "shadow" warnings. */
#define link link_shadow #define link link_shadow
/**
* strscpy - Copy a C-string into a sized buffer, but only if it fits
* @dest: Where to copy the string to
* @src: Where to copy the string from
* @size: size of destination buffer
*
* Use this routine to avoid copying too-long strings.
* The routine returns the total number of bytes copied
* (including the trailing NUL) or zero if the buffer wasn't
* big enough. To ensure that programmers pay attention
* to the return code, the destination has a single NUL
* written at the front (if size is non-zero) when the
* buffer is not big enough.
*/
static size_t strscpy(char *dest, const char *src, size_t size)
{
size_t len = strnlen(src, size) + 1;
if (len > size) {
if (size)
dest[0] = '\0';
return 0;
}
memcpy(dest, src, len);
return len;
}
int gxio_mpipe_init(gxio_mpipe_context_t *context, unsigned int mpipe_index) int gxio_mpipe_init(gxio_mpipe_context_t *context, unsigned int mpipe_index)
{ {
char file[32]; char file[32];
...@@ -537,7 +512,7 @@ int gxio_mpipe_link_instance(const char *link_name) ...@@ -537,7 +512,7 @@ int gxio_mpipe_link_instance(const char *link_name)
if (!context) if (!context)
return GXIO_ERR_NO_DEVICE; return GXIO_ERR_NO_DEVICE;
if (strscpy(name.name, link_name, sizeof(name.name)) == 0) if (strscpy(name.name, link_name, sizeof(name.name)) < 0)
return GXIO_ERR_NO_DEVICE; return GXIO_ERR_NO_DEVICE;
return gxio_mpipe_info_instance_aux(context, name); return gxio_mpipe_info_instance_aux(context, name);
...@@ -555,7 +530,7 @@ int gxio_mpipe_link_enumerate_mac(int idx, char *link_name, uint8_t *link_mac) ...@@ -555,7 +530,7 @@ int gxio_mpipe_link_enumerate_mac(int idx, char *link_name, uint8_t *link_mac)
rv = gxio_mpipe_info_enumerate_aux(context, idx, &name, &mac); rv = gxio_mpipe_info_enumerate_aux(context, idx, &name, &mac);
if (rv >= 0) { if (rv >= 0) {
if (strscpy(link_name, name.name, sizeof(name.name)) == 0) if (strscpy(link_name, name.name, sizeof(name.name)) < 0)
return GXIO_ERR_INVAL_MEMORY_SIZE; return GXIO_ERR_INVAL_MEMORY_SIZE;
memcpy(link_mac, mac.mac, sizeof(mac.mac)); memcpy(link_mac, mac.mac, sizeof(mac.mac));
} }
...@@ -572,7 +547,7 @@ int gxio_mpipe_link_open(gxio_mpipe_link_t *link, ...@@ -572,7 +547,7 @@ int gxio_mpipe_link_open(gxio_mpipe_link_t *link,
_gxio_mpipe_link_name_t name; _gxio_mpipe_link_name_t name;
int rv; int rv;
if (strscpy(name.name, link_name, sizeof(name.name)) == 0) if (strscpy(name.name, link_name, sizeof(name.name)) < 0)
return GXIO_ERR_NO_DEVICE; return GXIO_ERR_NO_DEVICE;
rv = gxio_mpipe_link_open_aux(context, name, flags); rv = gxio_mpipe_link_open_aux(context, name, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment