Remove assumption that kmalloc never fails.
Signed-off-by: NeilBrown <[email protected]>
---
Hi Chuck,
please squash this into the relevant patch - thanks.
Hi Dan,
thanks for the review!
NeilBrown
lib/lwq.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/lwq.c b/lib/lwq.c
index 8a723b29b39e..57d080a4d53d 100644
--- a/lib/lwq.c
+++ b/lib/lwq.c
@@ -111,6 +111,8 @@ static int lwq_test(void)
threads[i] = kthread_run(lwq_exercise, &q, "lwq-test-%d", i);
for (i = 0; i < 100; i++) {
t = kmalloc(sizeof(*t), GFP_KERNEL);
+ if (!t)
+ break;
t->i = i;
t->c = 0;
if (lwq_enqueue(&t->n, &q))
@@ -127,7 +129,8 @@ static int lwq_test(void)
printk(KERN_INFO " lwq: ... ");
}
t = lwq_dequeue(&q, struct tnode, n);
- printk(KERN_CONT " %d(%d)", t->i, t->c);
+ if (t)
+ printk(KERN_CONT " %d(%d)", t->i, t->c);
kfree(t);
}
printk(KERN_CONT "\n");
--
2.42.0
On Wed, Sep 27, 2023 at 06:11:52PM -0400, NeilBrown wrote:
>
> Remove assumption that kmalloc never fails.
>
> Signed-off-by: NeilBrown <[email protected]>
> ---
>
> Hi Chuck,
> please squash this into the relevant patch - thanks.
Done! Will update the public nfsd-next branch later today.
> Hi Dan,
> thanks for the review!
>
> NeilBrown
>
> lib/lwq.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/lwq.c b/lib/lwq.c
> index 8a723b29b39e..57d080a4d53d 100644
> --- a/lib/lwq.c
> +++ b/lib/lwq.c
> @@ -111,6 +111,8 @@ static int lwq_test(void)
> threads[i] = kthread_run(lwq_exercise, &q, "lwq-test-%d", i);
> for (i = 0; i < 100; i++) {
> t = kmalloc(sizeof(*t), GFP_KERNEL);
> + if (!t)
> + break;
> t->i = i;
> t->c = 0;
> if (lwq_enqueue(&t->n, &q))
> @@ -127,7 +129,8 @@ static int lwq_test(void)
> printk(KERN_INFO " lwq: ... ");
> }
> t = lwq_dequeue(&q, struct tnode, n);
> - printk(KERN_CONT " %d(%d)", t->i, t->c);
> + if (t)
> + printk(KERN_CONT " %d(%d)", t->i, t->c);
> kfree(t);
> }
> printk(KERN_CONT "\n");
> --
> 2.42.0
>
--
Chuck Lever