Skip to contentSkip to conversation

m68k: amiga: Mark sine_data as __initconst

PATCH In review Thorsten Blum 2 participants 4 messages Nov 8 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 m68k: amiga: Mark sine_data as __initconst

sine_data is only read by the __init function amiga_init_sound().

---
 arch/m68k/amiga/amisound.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/m68k/amiga/amisound.c +1 -1
index 5fd93dfab809..5ae1f017b39b 100644
@@ -19,7 +19,7 @@
 #include "amiga.h"
 
 static unsigned short *snd_data;
-static const signed char sine_data[] = {
+static const signed char sine_data[] __initconst = {
 	0,  39,  75,  103,  121,  127,  121,  103,  75,  39,
 	0, -39, -75, -103, -121, -127, -121, -103, -75, -39
 };
#1 lore raw

PATCH 2/2 m68k: amiga: Use clamp() in amiga_mksound()

Replace the open-coded period bounds checks with clamp() and remove the redundant comment.

---
 arch/m68k/amiga/amisound.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
arch/m68k/amiga/amisound.c +3 -9
index 5ae1f017b39b..5b9d265b2cac 100644
@@ -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);
 		custom.aud[2].audvol = 32; /* 50% of maxvol */
 
 		if (ticks) {
#2 lore raw

Re: [PATCH 2/2] m68k: amiga: Use clamp() in amiga_mksound()

Quoted 27 lines · On Sun, 8 Nov 2026 14:45:01 +0100 Thorsten Blum <[email protected]> wrote:

Replace the open-coded period bounds checks with clamp() and remove the redundant comment.

---
 arch/m68k/amiga/amisound.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
arch/m68k/amiga/amisound.c +1 -3
index 5ae1f017b39b..5b9d265b2cac 100644
@@ -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)

arch/m68k/amiga/amisound.c void amiga_mksound( unsigned int hz, unsigned int ticks ) · line 88

Quoted 10 lines
arch/m68k/amiga/amisound.c +2 -6
-			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

Quoted 4 lines
arch/m68k/amiga/amisound.c +0 -0
 		custom.aud[2].audvol = 32; /* 50% of maxvol */
 
 		if (ticks) {
#3 lore raw

Re: [PATCH 2/2] m68k: amiga: Use clamp() in amiga_mksound()

Quoted 26 lines · David Laight
Quoted 23 lines · On Sun, 8 Nov 2026 14:45:01 +0100 Thorsten Blum <[email protected]> wrote:

Replace the open-coded period bounds checks with clamp() and remove the redundant comment.

---
 arch/m68k/amiga/amisound.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
arch/m68k/amiga/amisound.c +1 -0
index 5ae1f017b39b..5b9d265b2cac 100644
@@ -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);
 
Quoted 16 lines
Quoted 4 lines
arch/m68k/amiga/amisound.c +0 -3
 	if (hz > 20 && hz < 32767) {
-		unsigned long period = (clock_constant / hz);
-
-		if (period < amiga_audio_min_period)

arch/m68k/amiga/amisound.c void amiga_mksound( unsigned int hz, unsigned int ticks ) · line 88

Quoted 10 lines
arch/m68k/amiga/amisound.c +2 -6
-			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.

amiga_audio_min_period is an unsigned short and can't exceed MAX_PERIOD, which is defined as 65535.