All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] sched: Use BUG_ON
@ 2021-07-01 14:11 ` Jason Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2021-07-01 14:11 UTC (permalink / raw)
  To: jk; +Cc: arnd, mpe, benh, paulus, linuxppc-dev, linux-kernel, Jason Wang

The BUG_ON macro simplifies the if condition followed by BUG, so that
we can use BUG_ON instead of if condition followed by BUG.

Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
---
 arch/powerpc/platforms/cell/spufs/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 369206489895..0f218d9e5733 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -904,8 +904,8 @@ static noinline void spusched_tick(struct spu_context *ctx)
 	struct spu_context *new = NULL;
 	struct spu *spu = NULL;
 
-	if (spu_acquire(ctx))
-		BUG();	/* a kernel thread never has signals pending */
+	/* a kernel thread never has signals pending */
+	BUG_ON(spu_acquire(ctx));
 
 	if (ctx->state != SPU_STATE_RUNNABLE)
 		goto out;
-- 
2.32.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] sched: Use BUG_ON
@ 2021-07-01 14:11 ` Jason Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2021-07-01 14:11 UTC (permalink / raw)
  To: jk; +Cc: arnd, linux-kernel, Jason Wang, paulus, linuxppc-dev

The BUG_ON macro simplifies the if condition followed by BUG, so that
we can use BUG_ON instead of if condition followed by BUG.

Signed-off-by: Jason Wang <wangborong@cdjrlc.com>
---
 arch/powerpc/platforms/cell/spufs/sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 369206489895..0f218d9e5733 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -904,8 +904,8 @@ static noinline void spusched_tick(struct spu_context *ctx)
 	struct spu_context *new = NULL;
 	struct spu *spu = NULL;
 
-	if (spu_acquire(ctx))
-		BUG();	/* a kernel thread never has signals pending */
+	/* a kernel thread never has signals pending */
+	BUG_ON(spu_acquire(ctx));
 
 	if (ctx->state != SPU_STATE_RUNNABLE)
 		goto out;
-- 
2.32.0




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched: Use BUG_ON
  2021-07-01 14:11 ` Jason Wang
@ 2021-07-02  1:19   ` Jeremy Kerr
  -1 siblings, 0 replies; 4+ messages in thread
From: Jeremy Kerr @ 2021-07-02  1:19 UTC (permalink / raw)
  To: Jason Wang; +Cc: arnd, mpe, benh, paulus, linuxppc-dev, linux-kernel

Hi Jason,

> The BUG_ON macro simplifies the if condition followed by BUG, so that
> we can use BUG_ON instead of if condition followed by BUG.

[...]

> -       if (spu_acquire(ctx))
> -               BUG();  /* a kernel thread never has signals pending */
> +       /* a kernel thread never has signals pending */
> +       BUG_ON(spu_acquire(ctx));

I'm not convinced that this is an improvement; you've combined the
acquire and the BUG into a single statement, and now it's no longer
clear what the comment applies to.

If you really wanted to use BUG_ON, something like this would be more
clear:

	rc = spu_acquire(ctx);
	/* a kernel thread never has signals pending */
	BUG_ON(rc);

but we don't have a suitable rc variable handy, so we'd need one of
those declared too. You could avoid that with:

	if (spu_acquire(ctx))
		BUG_ON(1); /* a kernel thread never has signals pending */

but wait: no need for the constant there, so this would be better:

	if (spu_acquire(ctx))
		BUG(); /* a kernel thread never has signals pending */

wait, what are we doing again?

To me, this is a bit of shuffling code around, for no real benefit.

Regards,


Jeremy


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched: Use BUG_ON
@ 2021-07-02  1:19   ` Jeremy Kerr
  0 siblings, 0 replies; 4+ messages in thread
From: Jeremy Kerr @ 2021-07-02  1:19 UTC (permalink / raw)
  To: Jason Wang; +Cc: arnd, linux-kernel, paulus, linuxppc-dev

Hi Jason,

> The BUG_ON macro simplifies the if condition followed by BUG, so that
> we can use BUG_ON instead of if condition followed by BUG.

[...]

> -       if (spu_acquire(ctx))
> -               BUG();  /* a kernel thread never has signals pending */
> +       /* a kernel thread never has signals pending */
> +       BUG_ON(spu_acquire(ctx));

I'm not convinced that this is an improvement; you've combined the
acquire and the BUG into a single statement, and now it's no longer
clear what the comment applies to.

If you really wanted to use BUG_ON, something like this would be more
clear:

	rc = spu_acquire(ctx);
	/* a kernel thread never has signals pending */
	BUG_ON(rc);

but we don't have a suitable rc variable handy, so we'd need one of
those declared too. You could avoid that with:

	if (spu_acquire(ctx))
		BUG_ON(1); /* a kernel thread never has signals pending */

but wait: no need for the constant there, so this would be better:

	if (spu_acquire(ctx))
		BUG(); /* a kernel thread never has signals pending */

wait, what are we doing again?

To me, this is a bit of shuffling code around, for no real benefit.

Regards,


Jeremy


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-02  1:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 14:11 [PATCH v2] sched: Use BUG_ON Jason Wang
2021-07-01 14:11 ` Jason Wang
2021-07-02  1:19 ` Jeremy Kerr
2021-07-02  1:19   ` Jeremy Kerr

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.