* [PATCH] lib/string.c: check for kmalloc() failure
@ 2017-08-17 11:54 Dan Carpenter
2017-08-17 12:28 ` walter harms
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2017-08-17 11:54 UTC (permalink / raw)
To: Andrew Morton, Matthew Wilcox
Cc: Stephen Rothwell, Kees Cook, Bjorn Helgaas,
Mauro Carvalho Chehab, Heikki Krogerus, Daniel Micay,
linux-kernel, kernel-janitors
This is mostly to keep the number of static checker warnings down so
we can spot new bugs instead of them being drowned in noise. This
function doesn't return normal kernel error codes but instead the return
value is used to display exactly which memory failed. I chose -1 as
hopefully that's a helpful thing to print.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/lib/string.c b/lib/string.c
index 661a6a6173c0..59e112cbcf22 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1058,7 +1058,11 @@ EXPORT_SYMBOL(fortify_overflow);
static __init int memset16_selftest(void)
{
unsigned i, j, k;
- u16 v, *p = kmalloc(256 * 2 * 2, GFP_KERNEL);
+ u16 v, *p;
+
+ p = kmalloc(256 * 2 * 2, GFP_KERNEL);
+ if (!p)
+ return -1;
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
@@ -1090,7 +1094,11 @@ static __init int memset16_selftest(void)
static __init int memset32_selftest(void)
{
unsigned i, j, k;
- u32 v, *p = kmalloc(256 * 2 * 4, GFP_KERNEL);
+ u32 v, *p;
+
+ p = kmalloc(256 * 2 * 4, GFP_KERNEL);
+ if (!p)
+ return -1;
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
@@ -1122,7 +1130,11 @@ static __init int memset32_selftest(void)
static __init int memset64_selftest(void)
{
unsigned i, j, k;
- u64 v, *p = kmalloc(256 * 2 * 8, GFP_KERNEL);
+ u64 v, *p;
+
+ p = kmalloc(256 * 2 * 8, GFP_KERNEL);
+ if (!p)
+ return -1;
for (i = 0; i < 256; i++) {
for (j = 0; j < 256; j++) {
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/string.c: check for kmalloc() failure
2017-08-17 11:54 [PATCH] lib/string.c: check for kmalloc() failure Dan Carpenter
@ 2017-08-17 12:28 ` walter harms
0 siblings, 0 replies; 2+ messages in thread
From: walter harms @ 2017-08-17 12:28 UTC (permalink / raw)
To: kernel-janitors
Am 17.08.2017 13:54, schrieb Dan Carpenter:
> This is mostly to keep the number of static checker warnings down so
> we can spot new bugs instead of them being drowned in noise. This
> function doesn't return normal kernel error codes but instead the return
> value is used to display exactly which memory failed. I chose -1 as
> hopefully that's a helpful thing to print.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/lib/string.c b/lib/string.c
> index 661a6a6173c0..59e112cbcf22 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -1058,7 +1058,11 @@ EXPORT_SYMBOL(fortify_overflow);
> static __init int memset16_selftest(void)
> {
> unsigned i, j, k;
> - u16 v, *p = kmalloc(256 * 2 * 2, GFP_KERNEL);
> + u16 v, *p;
> +
> + p = kmalloc(256 * 2 * 2, GFP_KERNEL);
> + if (!p)
> + return -1;
>
> for (i = 0; i < 256; i++) {
> for (j = 0; j < 256; j++) {
> @@ -1090,7 +1094,11 @@ static __init int memset16_selftest(void)
> static __init int memset32_selftest(void)
> {
> unsigned i, j, k;
> - u32 v, *p = kmalloc(256 * 2 * 4, GFP_KERNEL);
> + u32 v, *p;
> +
> + p = kmalloc(256 * 2 * 4, GFP_KERNEL);
> + if (!p)
> + return -1;
>
> for (i = 0; i < 256; i++) {
> for (j = 0; j < 256; j++) {
> @@ -1122,7 +1130,11 @@ static __init int memset32_selftest(void)
> static __init int memset64_selftest(void)
> {
> unsigned i, j, k;
> - u64 v, *p = kmalloc(256 * 2 * 8, GFP_KERNEL);
> + u64 v, *p;
> +
> + p = kmalloc(256 * 2 * 8, GFP_KERNEL);
> + if (!p)
> + return -1;
I assume that the multiplier 2/4/8 means sizeof(uX).
The 256 is an arbitrary block size but the *2 left me puzzled.
Could anybody (not necessarily Dan) drop a few helpful comments
for these numbers ?
re,
wh
>
> for (i = 0; i < 256; i++) {
> for (j = 0; j < 256; j++) {
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-17 12:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-17 11:54 [PATCH] lib/string.c: check for kmalloc() failure Dan Carpenter
2017-08-17 12:28 ` walter harms
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).