nlattr.c (9ca718743ad8402958637bfc196d7b62371a1b9f) nlattr.c (872f690341948b502c93318f806d821c56772c42)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * NETLINK Netlink attributes
4 *
5 * Authors: Thomas Graf <tgraf@suug.ch>
6 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
7 */
8

--- 695 unchanged lines hidden (view full) ---

704 if (nla_type(nla) == attrtype)
705 return (struct nlattr *)nla;
706
707 return NULL;
708}
709EXPORT_SYMBOL(nla_find);
710
711/**
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * NETLINK Netlink attributes
4 *
5 * Authors: Thomas Graf <tgraf@suug.ch>
6 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
7 */
8

--- 695 unchanged lines hidden (view full) ---

704 if (nla_type(nla) == attrtype)
705 return (struct nlattr *)nla;
706
707 return NULL;
708}
709EXPORT_SYMBOL(nla_find);
710
711/**
712 * nla_strlcpy - Copy string attribute payload into a sized buffer
712 * nla_strscpy - Copy string attribute payload into a sized buffer
713 * @dst: Where to copy the string to.
714 * @nla: Attribute to copy the string from.
715 * @dstsize: Size of destination buffer.
716 *
717 * Copies at most dstsize - 1 bytes into the destination buffer.
718 * Unlike strlcpy the destination buffer is always padded out.
719 *
720 * Return:
721 * * srclen - Returns @nla length (not including the trailing %NUL).
722 * * -E2BIG - If @dstsize is 0 or greater than U16_MAX or @nla length greater
723 * than @dstsize.
724 */
713 * @dst: Where to copy the string to.
714 * @nla: Attribute to copy the string from.
715 * @dstsize: Size of destination buffer.
716 *
717 * Copies at most dstsize - 1 bytes into the destination buffer.
718 * Unlike strlcpy the destination buffer is always padded out.
719 *
720 * Return:
721 * * srclen - Returns @nla length (not including the trailing %NUL).
722 * * -E2BIG - If @dstsize is 0 or greater than U16_MAX or @nla length greater
723 * than @dstsize.
724 */
725ssize_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
725ssize_t nla_strscpy(char *dst, const struct nlattr *nla, size_t dstsize)
726{
727 size_t srclen = nla_len(nla);
728 char *src = nla_data(nla);
729 ssize_t ret;
730 size_t len;
731
732 if (dstsize == 0 || WARN_ON_ONCE(dstsize > U16_MAX))
733 return -E2BIG;

--- 10 unchanged lines hidden (view full) ---

744 }
745
746 memcpy(dst, src, len);
747 /* Zero pad end of dst. */
748 memset(dst + len, 0, dstsize - len);
749
750 return ret;
751}
726{
727 size_t srclen = nla_len(nla);
728 char *src = nla_data(nla);
729 ssize_t ret;
730 size_t len;
731
732 if (dstsize == 0 || WARN_ON_ONCE(dstsize > U16_MAX))
733 return -E2BIG;

--- 10 unchanged lines hidden (view full) ---

744 }
745
746 memcpy(dst, src, len);
747 /* Zero pad end of dst. */
748 memset(dst + len, 0, dstsize - len);
749
750 return ret;
751}
752EXPORT_SYMBOL(nla_strlcpy);
752EXPORT_SYMBOL(nla_strscpy);
753
754/**
755 * nla_strdup - Copy string attribute payload into a newly allocated buffer
756 * @nla: attribute to copy the string from
757 * @flags: the type of memory to allocate (see kmalloc).
758 *
759 * Returns a pointer to the allocated buffer or NULL on error.
760 */

--- 362 unchanged lines hidden ---
753
754/**
755 * nla_strdup - Copy string attribute payload into a newly allocated buffer
756 * @nla: attribute to copy the string from
757 * @flags: the type of memory to allocate (see kmalloc).
758 *
759 * Returns a pointer to the allocated buffer or NULL on error.
760 */

--- 362 unchanged lines hidden ---