aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/string.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-09-09 15:49:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-09 15:49:01 -0400
commit126e76ffbf78d9e948b641aadb265d16c57f5a3d (patch)
tree656e7838f0ec057936b80e15a774911df05c6005 /include/linux/string.h
parentfbd01410e89a66f346ba1b3c0161e1198449b746 (diff)
parent175206cf9ab63161dec74d9cd7f9992e062491f5 (diff)
Merge branch 'for-4.14/block-postmerge' of git://git.kernel.dk/linux-block
Pull followup block layer updates from Jens Axboe: "I ended up splitting the main pull request for this series into two, mainly because of clashes between NVMe fixes that went into 4.13 after the for-4.14 branches were split off. This pull request is mostly NVMe, but not exclusively. In detail, it contains: - Two pull request for NVMe changes from Christoph. Nothing new on the feature front, basically just fixes all over the map for the core bits, transport, rdma, etc. - Series from Bart, cleaning up various bits in the BFQ scheduler. - Series of bcache fixes, which has been lingering for a release or two. Coly sent this in, but patches from various people in this area. - Set of patches for BFQ from Paolo himself, updating both documentation and fixing some corner cases in performance. - Series from Omar, attempting to now get the 4k loop support correct. Our confidence level is higher this time. - Series from Shaohua for loop as well, improving O_DIRECT performance and fixing a use-after-free" * 'for-4.14/block-postmerge' of git://git.kernel.dk/linux-block: (74 commits) bcache: initialize dirty stripes in flash_dev_run() loop: set physical block size to logical block size bcache: fix bch_hprint crash and improve output bcache: Update continue_at() documentation bcache: silence static checker warning bcache: fix for gc and write-back race bcache: increase the number of open buckets bcache: Correct return value for sysfs attach errors bcache: correct cache_dirty_target in __update_writeback_rate() bcache: gc does not work when triggering by manual command bcache: Don't reinvent the wheel but use existing llist API bcache: do not subtract sectors_to_gc for bypassed IO bcache: fix sequential large write IO bypass bcache: Fix leak of bdev reference block/loop: remove unused field block/loop: fix use after free bfq: Use icq_to_bic() consistently bfq: Suppress compiler warnings about comparisons bfq: Check kstrtoul() return value bfq: Declare local functions static ...
Diffstat (limited to 'include/linux/string.h')
-rw-r--r--include/linux/string.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/string.h b/include/linux/string.h
index c8bdafffd2f0..e1eeb0a8a969 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -230,6 +230,7 @@ static inline const char *kbasename(const char *path)
230void fortify_panic(const char *name) __noreturn __cold; 230void fortify_panic(const char *name) __noreturn __cold;
231void __read_overflow(void) __compiletime_error("detected read beyond size of object passed as 1st parameter"); 231void __read_overflow(void) __compiletime_error("detected read beyond size of object passed as 1st parameter");
232void __read_overflow2(void) __compiletime_error("detected read beyond size of object passed as 2nd parameter"); 232void __read_overflow2(void) __compiletime_error("detected read beyond size of object passed as 2nd parameter");
233void __read_overflow3(void) __compiletime_error("detected read beyond size of object passed as 3rd parameter");
233void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter"); 234void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter");
234 235
235#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE) 236#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
@@ -425,4 +426,33 @@ __FORTIFY_INLINE char *strcpy(char *p, const char *q)
425 426
426#endif 427#endif
427 428
429/**
430 * memcpy_and_pad - Copy one buffer to another with padding
431 * @dest: Where to copy to
432 * @dest_len: The destination buffer size
433 * @src: Where to copy from
434 * @count: The number of bytes to copy
435 * @pad: Character to use for padding if space is left in destination.
436 */
437__FORTIFY_INLINE void memcpy_and_pad(void *dest, size_t dest_len,
438 const void *src, size_t count, int pad)
439{
440 size_t dest_size = __builtin_object_size(dest, 0);
441 size_t src_size = __builtin_object_size(src, 0);
442
443 if (__builtin_constant_p(dest_len) && __builtin_constant_p(count)) {
444 if (dest_size < dest_len && dest_size < count)
445 __write_overflow();
446 else if (src_size < dest_len && src_size < count)
447 __read_overflow3();
448 }
449 if (dest_size < dest_len)
450 fortify_panic(__func__);
451 if (dest_len > count) {
452 memcpy(dest, src, count);
453 memset(dest + count, pad, dest_len - count);
454 } else
455 memcpy(dest, src, dest_len);
456}
457
428#endif /* _LINUX_STRING_H_ */ 458#endif /* _LINUX_STRING_H_ */