]> Git Repo - linux.git/commitdiff
Merge tag 'fallthrough-fixes-clang-5.11-rc1' of git://git.kernel.org/pub/scm/linux...
authorLinus Torvalds <[email protected]>
Wed, 16 Dec 2020 08:24:16 +0000 (00:24 -0800)
committerLinus Torvalds <[email protected]>
Wed, 16 Dec 2020 08:24:16 +0000 (00:24 -0800)
Pull fallthrough fixes from Gustavo A. R. Silva:
 "Fix many fall-through warnings when building with Clang 12.0.0
  using -Wimplicit-fallthrough.

   - powerpc: boot: include compiler_attributes.h (Nick Desaulniers)

   - Revert "lib: Revert use of fallthrough pseudo-keyword in lib/"
     (Nick Desaulniers)

   - powerpc: fix -Wimplicit-fallthrough (Nick Desaulniers)

   - lib: Fix fall-through warnings for Clang (Gustavo A. R. Silva)"

* tag 'fallthrough-fixes-clang-5.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux:
  lib: Fix fall-through warnings for Clang
  powerpc: fix -Wimplicit-fallthrough
  Revert "lib: Revert use of fallthrough pseudo-keyword in lib/"
  powerpc: boot: include compiler_attributes.h

1  2 
lib/cmdline.c
lib/nlattr.c

diff --combined lib/cmdline.c
index 9e186234edc0b8e1ad37cb8a3e7e1d5b95071071,d11fdc57917099b93cf87823531e395f6661dbc8..b390dd03363bd093a2a270881e1059cb79f96467
@@@ -35,37 -35,25 +35,37 @@@ static int get_range(char **str, int *p
  /**
   *    get_option - Parse integer from an option string
   *    @str: option string
 - *    @pint: (output) integer value parsed from @str
 + *    @pint: (optional output) integer value parsed from @str
   *
   *    Read an int from an option string; if available accept a subsequent
   *    comma as well.
   *
 + *    When @pint is NULL the function can be used as a validator of
 + *    the current option in the string.
 + *
   *    Return values:
   *    0 - no int in string
   *    1 - int found, no subsequent comma
   *    2 - int found including a subsequent comma
   *    3 - hyphen found to denote a range
 + *
 + *    Leading hyphen without integer is no integer case, but we consume it
 + *    for the sake of simplification.
   */
  
  int get_option(char **str, int *pint)
  {
        char *cur = *str;
 +      int value;
  
        if (!cur || !(*cur))
                return 0;
 -      *pint = simple_strtol(cur, str, 0);
 +      if (*cur == '-')
 +              value = -simple_strtoull(++cur, str, 0);
 +      else
 +              value = simple_strtoull(cur, str, 0);
 +      if (pint)
 +              *pint = value;
        if (cur == *str)
                return 0;
        if (**str == ',') {
@@@ -144,27 -132,28 +144,28 @@@ unsigned long long memparse(const char 
        case 'E':
        case 'e':
                ret <<= 10;
-               /* fall through */
+               fallthrough;
        case 'P':
        case 'p':
                ret <<= 10;
-               /* fall through */
+               fallthrough;
        case 'T':
        case 't':
                ret <<= 10;
-               /* fall through */
+               fallthrough;
        case 'G':
        case 'g':
                ret <<= 10;
-               /* fall through */
+               fallthrough;
        case 'M':
        case 'm':
                ret <<= 10;
-               /* fall through */
+               fallthrough;
        case 'K':
        case 'k':
                ret <<= 10;
                endptr++;
+               fallthrough;
        default:
                break;
        }
diff --combined lib/nlattr.c
index 09aa181569e03a4fe283fed5da70ac4096dedc57,19372355557ab583eaff71eebec6bea365db6763..5b6116e81f9f206462d691e5af52aa3044fd900e
@@@ -432,7 -432,7 +432,7 @@@ static int validate_nla(const struct nl
                        err = -EINVAL;
                        goto out_err;
                }
-               /* fall through */
+               fallthrough;
  
        case NLA_STRING:
                if (attrlen < 1)
@@@ -709,47 -709,35 +709,47 @@@ struct nlattr *nla_find(const struct nl
  EXPORT_SYMBOL(nla_find);
  
  /**
 - * nla_strlcpy - Copy string attribute payload into a sized buffer
 - * @dst: where to copy the string to
 - * @nla: attribute to copy the string from
 - * @dstsize: size of destination buffer
 + * nla_strscpy - Copy string attribute payload into a sized buffer
 + * @dst: Where to copy the string to.
 + * @nla: Attribute to copy the string from.
 + * @dstsize: Size of destination buffer.
   *
   * Copies at most dstsize - 1 bytes into the destination buffer.
 - * The result is always a valid NUL-terminated string. Unlike
 - * strlcpy the destination buffer is always padded out.
 + * Unlike strlcpy the destination buffer is always padded out.
   *
 - * Returns the length of the source buffer.
 + * Return:
 + * * srclen - Returns @nla length (not including the trailing %NUL).
 + * * -E2BIG - If @dstsize is 0 or greater than U16_MAX or @nla length greater
 + *            than @dstsize.
   */
 -size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
 +ssize_t nla_strscpy(char *dst, const struct nlattr *nla, size_t dstsize)
  {
        size_t srclen = nla_len(nla);
        char *src = nla_data(nla);
 +      ssize_t ret;
 +      size_t len;
 +
 +      if (dstsize == 0 || WARN_ON_ONCE(dstsize > U16_MAX))
 +              return -E2BIG;
  
        if (srclen > 0 && src[srclen - 1] == '\0')
                srclen--;
  
 -      if (dstsize > 0) {
 -              size_t len = (srclen >= dstsize) ? dstsize - 1 : srclen;
 -
 -              memset(dst, 0, dstsize);
 -              memcpy(dst, src, len);
 +      if (srclen >= dstsize) {
 +              len = dstsize - 1;
 +              ret = -E2BIG;
 +      } else {
 +              len = srclen;
 +              ret = len;
        }
  
 -      return srclen;
 +      memcpy(dst, src, len);
 +      /* Zero pad end of dst. */
 +      memset(dst + len, 0, dstsize - len);
 +
 +      return ret;
  }
 -EXPORT_SYMBOL(nla_strlcpy);
 +EXPORT_SYMBOL(nla_strscpy);
  
  /**
   * nla_strdup - Copy string attribute payload into a newly allocated buffer
This page took 0.070843 seconds and 4 git commands to generate.