diff options
| author | Takashi Iwai <tiwai@suse.de> | 2024-12-05 20:09:29 +0300 |
|---|---|---|
| committer | Takashi Iwai <tiwai@suse.de> | 2024-12-05 20:09:29 +0300 |
| commit | c34e9ab9a612ee8b18273398ef75c207b01f516d (patch) | |
| tree | 6845a1809118a2b2a21d5a638ace1976dd8f8c46 /lib/string.c | |
| parent | 20c3b3e5f2641eff3d85f33e6a468ac052b169bd (diff) | |
| parent | ec16a3cdf37e507013062f9c4a2067eacdd12b62 (diff) | |
| download | linux-c34e9ab9a612ee8b18273398ef75c207b01f516d.tar.xz | |
Merge tag 'asoc-fix-v6.13-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-linus
ASoC: Fixes for v6.13
A few small fixes for v6.13, all system specific - the biggest thing is
the fix for jack handling over suspend on some Intel laptops.
Diffstat (limited to 'lib/string.c')
| -rw-r--r-- | lib/string.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/string.c b/lib/string.c index 76327b51e36f..eb4486ed40d2 100644 --- a/lib/string.c +++ b/lib/string.c @@ -104,6 +104,12 @@ char *strncpy(char *dest, const char *src, size_t count) EXPORT_SYMBOL(strncpy); #endif +#ifdef __BIG_ENDIAN +# define ALLBUTLAST_BYTE_MASK (~255ul) +#else +# define ALLBUTLAST_BYTE_MASK (~0ul >> 8) +#endif + ssize_t sized_strscpy(char *dest, const char *src, size_t count) { const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; @@ -147,13 +153,18 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count) *(unsigned long *)(dest+res) = c & zero_bytemask(data); return res + find_zero(data); } + count -= sizeof(unsigned long); + if (unlikely(!count)) { + c &= ALLBUTLAST_BYTE_MASK; + *(unsigned long *)(dest+res) = c; + return -E2BIG; + } *(unsigned long *)(dest+res) = c; res += sizeof(unsigned long); - count -= sizeof(unsigned long); max -= sizeof(unsigned long); } - while (count) { + while (count > 1) { char c; c = src[res]; @@ -164,11 +175,11 @@ ssize_t sized_strscpy(char *dest, const char *src, size_t count) count--; } - /* Hit buffer length without finding a NUL; force NUL-termination. */ - if (res) - dest[res-1] = '\0'; + /* Force NUL-termination. */ + dest[res] = '\0'; - return -E2BIG; + /* Return E2BIG if the source didn't stop */ + return src[res] ? -E2BIG : res; } EXPORT_SYMBOL(sized_strscpy); |
