aboutsummaryrefslogtreecommitdiffstats
path: root/arch/tile/gxio/mpipe.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/tile/gxio/mpipe.c')
-rw-r--r--arch/tile/gxio/mpipe.c33
1 files changed, 4 insertions, 29 deletions
diff --git a/arch/tile/gxio/mpipe.c b/arch/tile/gxio/mpipe.c
index ee186e13dfe6..f102048d9c0e 100644
--- a/arch/tile/gxio/mpipe.c
+++ b/arch/tile/gxio/mpipe.c
@@ -19,6 +19,7 @@
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/string.h>
22 23
23#include <gxio/iorpc_globals.h> 24#include <gxio/iorpc_globals.h>
24#include <gxio/iorpc_mpipe.h> 25#include <gxio/iorpc_mpipe.h>
@@ -29,32 +30,6 @@
29/* HACK: Avoid pointless "shadow" warnings. */ 30/* HACK: Avoid pointless "shadow" warnings. */
30#define link link_shadow 31#define link link_shadow
31 32
32/**
33 * strscpy - Copy a C-string into a sized buffer, but only if it fits
34 * @dest: Where to copy the string to
35 * @src: Where to copy the string from
36 * @size: size of destination buffer
37 *
38 * Use this routine to avoid copying too-long strings.
39 * The routine returns the total number of bytes copied
40 * (including the trailing NUL) or zero if the buffer wasn't
41 * big enough. To ensure that programmers pay attention
42 * to the return code, the destination has a single NUL
43 * written at the front (if size is non-zero) when the
44 * buffer is not big enough.
45 */
46static size_t strscpy(char *dest, const char *src, size_t size)
47{
48 size_t len = strnlen(src, size) + 1;
49 if (len > size) {
50 if (size)
51 dest[0] = '\0';
52 return 0;
53 }
54 memcpy(dest, src, len);
55 return len;
56}
57
58int gxio_mpipe_init(gxio_mpipe_context_t *context, unsigned int mpipe_index) 33int gxio_mpipe_init(gxio_mpipe_context_t *context, unsigned int mpipe_index)
59{ 34{
60 char file[32]; 35 char file[32];
@@ -540,7 +515,7 @@ int gxio_mpipe_link_instance(const char *link_name)
540 if (!context) 515 if (!context)
541 return GXIO_ERR_NO_DEVICE; 516 return GXIO_ERR_NO_DEVICE;
542 517
543 if (strscpy(name.name, link_name, sizeof(name.name)) == 0) 518 if (strscpy(name.name, link_name, sizeof(name.name)) < 0)
544 return GXIO_ERR_NO_DEVICE; 519 return GXIO_ERR_NO_DEVICE;
545 520
546 return gxio_mpipe_info_instance_aux(context, name); 521 return gxio_mpipe_info_instance_aux(context, name);
@@ -559,7 +534,7 @@ int gxio_mpipe_link_enumerate_mac(int idx, char *link_name, uint8_t *link_mac)
559 534
560 rv = gxio_mpipe_info_enumerate_aux(context, idx, &name, &mac); 535 rv = gxio_mpipe_info_enumerate_aux(context, idx, &name, &mac);
561 if (rv >= 0) { 536 if (rv >= 0) {
562 if (strscpy(link_name, name.name, sizeof(name.name)) == 0) 537 if (strscpy(link_name, name.name, sizeof(name.name)) < 0)
563 return GXIO_ERR_INVAL_MEMORY_SIZE; 538 return GXIO_ERR_INVAL_MEMORY_SIZE;
564 memcpy(link_mac, mac.mac, sizeof(mac.mac)); 539 memcpy(link_mac, mac.mac, sizeof(mac.mac));
565 } 540 }
@@ -576,7 +551,7 @@ int gxio_mpipe_link_open(gxio_mpipe_link_t *link,
576 _gxio_mpipe_link_name_t name; 551 _gxio_mpipe_link_name_t name;
577 int rv; 552 int rv;
578 553
579 if (strscpy(name.name, link_name, sizeof(name.name)) == 0) 554 if (strscpy(name.name, link_name, sizeof(name.name)) < 0)
580 return GXIO_ERR_NO_DEVICE; 555 return GXIO_ERR_NO_DEVICE;
581 556
582 rv = gxio_mpipe_link_open_aux(context, name, flags); 557 rv = gxio_mpipe_link_open_aux(context, name, flags);