mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Thorsten Blum <blum@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
	linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] m68k: amiga: Use clamp() in amiga_mksound()
Date: Sun, 8 Nov 2026 22:58:48 +0000	[thread overview]
Message-ID: <20261108225848.2b643170@pumpkin> (raw)
In-Reply-To: <20261108134501.404852-4-blum@kernel.org>

On Sun,  8 Nov 2026 14:45:01 +0100
Thorsten Blum <blum@kernel.org> wrote:

> Replace the open-coded period bounds checks with clamp() and remove the
> redundant comment.
> 
> Signed-off-by: Thorsten Blum <blum@kernel.org>
> ---
>  arch/m68k/amiga/amisound.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/m68k/amiga/amisound.c b/arch/m68k/amiga/amisound.c
> index 5ae1f017b39b..5b9d265b2cac 100644
> --- a/arch/m68k/amiga/amisound.c
> +++ b/arch/m68k/amiga/amisound.c
> @@ -12,6 +12,7 @@
>  #include <linux/timer.h>
>  #include <linux/init.h>
>  #include <linux/string.h>
> +#include <linux/minmax.h>
>  #include <linux/module.h>
>  
>  #include <asm/amigahw.h>
> @@ -81,17 +82,10 @@ void amiga_mksound( unsigned int hz, unsigned int ticks )
>  	timer_delete(&sound_timer);
>  
>  	if (hz > 20 && hz < 32767) {
> -		unsigned long period = (clock_constant / hz);
> -
> -		if (period < amiga_audio_min_period)
> -			period = amiga_audio_min_period;
> -		if (period > MAX_PERIOD)
> -			period = MAX_PERIOD;
> -
> -		/* setup pointer to data, period, length and volume */
>  		custom.aud[2].audlc = snd_data;
>  		custom.aud[2].audlen = sizeof(sine_data)/2;
> -		custom.aud[2].audper = (unsigned short)period;
> +		custom.aud[2].audper = clamp(clock_constant / hz,
> +					     amiga_audio_min_period, MAX_PERIOD);

That requires that amiga_audio_min_period be less than MAX_PERIOD.
The order clamp() does the compares in is undefined.
I think it currently does high then low. (IIRC it got swapped a few years
back by a commit that said it didn't change anything!)

I've thought about proposing swapping the order and then allowing:
	clamp(int_var, 0, unsigned_limit);

David

>  		custom.aud[2].audvol = 32; /* 50% of maxvol */
>  
>  		if (ticks) {
> 


  reply	other threads:[~2026-11-08 22:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08 13:45 [PATCH 1/2] m68k: amiga: Mark sine_data as __initconst Thorsten Blum
2026-11-08 13:45 ` [PATCH 2/2] m68k: amiga: Use clamp() in amiga_mksound() Thorsten Blum
2026-11-08 22:58   ` David Laight [this message]
2026-11-08 23:22     ` Thorsten Blum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261108225848.2b643170@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=blum@kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®