From: Len Bao <len.bao@gmx.us>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Ivan Orlov <ivan.orlov0322@gmail.com>
Cc: Len Bao <len.bao@gmx.us>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ALSA: drivers: Mark some variables as __ro_after_init
Date: Sun, 24 May 2026 16:52:48 +0000	[thread overview]
Message-ID: <20260524165249.48941-1-len.bao@gmx.us> (raw)

Some variables in the 'ALSA/drivers' are initialized only during the
init phase in the '__init' functions and never changed. So, mark them
as __ro_after_init to reduce the attack surface.

Signed-off-by: Len Bao <len.bao@gmx.us>
---
 sound/drivers/mpu401/mpu401.c | 2 +-
 sound/drivers/pcmtest.c       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c
index d3f942408..b615a310c 100644
--- a/sound/drivers/mpu401/mpu401.c
+++ b/sound/drivers/mpu401/mpu401.c
@@ -46,7 +46,7 @@ module_param_array(uart_enter, bool, NULL, 0444);
 MODULE_PARM_DESC(uart_enter, "Issue UART_ENTER command at open.");
 
 static struct platform_device *platform_devices[SNDRV_CARDS];
-static int pnp_registered;
+static int pnp_registered __ro_after_init;
 static unsigned int snd_mpu401_devices;
 
 static int snd_mpu401_create(struct device *devptr, int dev,
diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c
index 7f93557b5..5d5281e4d 100644
--- a/sound/drivers/pcmtest.c
+++ b/sound/drivers/pcmtest.c
@@ -113,7 +113,7 @@ struct pcmtst_buf_iter {
 	struct timer_list timer_instance;
 };
 
-static struct snd_pcm_hardware snd_pcmtst_hw = {
+static struct snd_pcm_hardware snd_pcmtst_hw __ro_after_init = {
 	.info = (SNDRV_PCM_INFO_INTERLEAVED |
 		 SNDRV_PCM_INFO_BLOCK_TRANSFER |
 		 SNDRV_PCM_INFO_NONINTERLEAVED |
@@ -137,7 +137,7 @@ struct pattern_buf {
 	u32 len;
 };
 
-static int buf_allocated;
+static int buf_allocated __ro_after_init;
 static struct pattern_buf patt_bufs[MAX_CHANNELS_NUM];
 
 static inline void inc_buf_pos(struct pcmtst_buf_iter *v_iter, size_t by, size_t bytes)
-- 
2.43.0


             reply	other threads:[~2026-05-24 16:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 16:52 Len Bao [this message]
2026-05-25  7:32 ` [PATCH] ALSA: drivers: Mark some variables as __ro_after_init Takashi Iwai

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=20260524165249.48941-1-len.bao@gmx.us \
    --to=len.bao@gmx.us \
    --cc=ivan.orlov0322@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /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 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.