diff mbox series

[nfsd] SQUASH 8dc9e02aed76 lib: add light-weight queuing mechanism.

Message ID 169585271242.5939.14975098525477744646@noble.neil.brown.name (mailing list archive)
State New, archived
Headers show
Series [nfsd] SQUASH 8dc9e02aed76 lib: add light-weight queuing mechanism. | expand

Commit Message

NeilBrown Sept. 27, 2023, 10:11 p.m. UTC
Remove assumption that kmalloc never fails.

Signed-off-by: NeilBrown <neilb@suse.de>
---

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(-)

Comments

Chuck Lever Sept. 28, 2023, 1:42 p.m. UTC | #1
On Wed, Sep 27, 2023 at 06:11:52PM -0400, NeilBrown wrote:
> 
> Remove assumption that kmalloc never fails.
> 
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
> 
> 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
>
diff mbox series

Patch

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");