From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Subject: [PATCH 02/14] ALSA: pcm: Drop __force casts
Date: Wed, 12 Aug 2026 08:04:34 +0200 [thread overview]
Message-ID: <20260812060557.80445-3-tiwai@suse.de> (raw)
In-Reply-To: <20260812060557.80445-1-tiwai@suse.de>
Now that the bitwise parameter definitions are gone for PCM
parameters, we don't have to cast with ugly __force prefix.
Simply drop those superfluous casts.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
include/sound/pcm.h | 10 ++++------
include/sound/pcm_params.h | 13 +++++--------
sound/core/pcm.c | 12 +++++-------
sound/core/pcm_misc.c | 25 +++++++++++--------------
sound/core/pcm_native.c | 28 ++++++++++++++--------------
5 files changed, 39 insertions(+), 49 deletions(-)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 76fc33dce537..ab96396a7444 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -145,7 +145,7 @@ struct snd_pcm_ops {
#define SNDRV_PCM_RATE_8000_768000 (SNDRV_PCM_RATE_8000_384000|\
SNDRV_PCM_RATE_705600|\
SNDRV_PCM_RATE_768000)
-#define _SNDRV_PCM_FMTBIT(fmt) (1ULL << (__force int)SNDRV_PCM_FORMAT_##fmt)
+#define _SNDRV_PCM_FMTBIT(fmt) (1ULL << SNDRV_PCM_FORMAT_##fmt)
#define SNDRV_PCM_FMTBIT_S8 _SNDRV_PCM_FMTBIT(S8)
#define SNDRV_PCM_FMTBIT_U8 _SNDRV_PCM_FMTBIT(U8)
#define SNDRV_PCM_FMTBIT_S16_LE _SNDRV_PCM_FMTBIT(S16_LE)
@@ -228,7 +228,7 @@ struct snd_pcm_ops {
#define SNDRV_PCM_FMTBIT_U20 SNDRV_PCM_FMTBIT_U20_BE
#endif
-#define _SNDRV_PCM_SUBFMTBIT(fmt) BIT((__force int)SNDRV_PCM_SUBFORMAT_##fmt)
+#define _SNDRV_PCM_SUBFMTBIT(fmt) BIT(SNDRV_PCM_SUBFORMAT_##fmt)
#define SNDRV_PCM_SUBFMTBIT_STD _SNDRV_PCM_SUBFMTBIT(STD)
#define SNDRV_PCM_SUBFMTBIT_MSBITS_MAX _SNDRV_PCM_SUBFMTBIT(MSBITS_MAX)
#define SNDRV_PCM_SUBFMTBIT_MSBITS_20 _SNDRV_PCM_SUBFMTBIT(MSBITS_20)
@@ -1515,7 +1515,7 @@ int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
*/
static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
{
- return 1ULL << (__force int) pcm_format;
+ return 1ULL << pcm_format;
}
/**
@@ -1523,9 +1523,7 @@ static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
* @f: the iterator variable in snd_pcm_format_t type
*/
#define pcm_for_each_format(f) \
- for ((f) = SNDRV_PCM_FORMAT_FIRST; \
- (__force int)(f) <= (__force int)SNDRV_PCM_FORMAT_LAST; \
- (f) = (__force snd_pcm_format_t)((__force int)(f) + 1))
+ for ((f) = SNDRV_PCM_FORMAT_FIRST; (f) <= SNDRV_PCM_FORMAT_LAST; (f)++)
/* printk helpers */
#define pcm_err(pcm, fmt, args...) \
diff --git a/include/sound/pcm_params.h b/include/sound/pcm_params.h
index fbf35df6e5cf..bc43955fcb76 100644
--- a/include/sound/pcm_params.h
+++ b/include/sound/pcm_params.h
@@ -71,7 +71,7 @@ static inline void snd_mask_set(struct snd_mask *mask, unsigned int val)
static inline void snd_mask_set_format(struct snd_mask *mask,
snd_pcm_format_t format)
{
- snd_mask_set(mask, (__force unsigned int)format);
+ snd_mask_set(mask, format);
}
static inline void snd_mask_reset(struct snd_mask *mask, unsigned int val)
@@ -132,7 +132,7 @@ static inline int snd_mask_test(const struct snd_mask *mask, unsigned int val)
static inline int snd_mask_test_format(const struct snd_mask *mask,
snd_pcm_format_t format)
{
- return snd_mask_test(mask, (__force unsigned int)format);
+ return snd_mask_test(mask, format);
}
static inline int snd_mask_single(const struct snd_mask *mask)
@@ -302,8 +302,7 @@ static inline int snd_interval_eq(const struct snd_interval *i1, const struct sn
*/
static inline snd_pcm_access_t params_access(const struct snd_pcm_hw_params *p)
{
- return (__force snd_pcm_access_t)snd_mask_min(hw_param_mask_c(p,
- SNDRV_PCM_HW_PARAM_ACCESS));
+ return snd_mask_min(hw_param_mask_c(p, SNDRV_PCM_HW_PARAM_ACCESS));
}
/**
@@ -312,8 +311,7 @@ static inline snd_pcm_access_t params_access(const struct snd_pcm_hw_params *p)
*/
static inline snd_pcm_format_t params_format(const struct snd_pcm_hw_params *p)
{
- return (__force snd_pcm_format_t)snd_mask_min(hw_param_mask_c(p,
- SNDRV_PCM_HW_PARAM_FORMAT));
+ return snd_mask_min(hw_param_mask_c(p, SNDRV_PCM_HW_PARAM_FORMAT));
}
/**
@@ -323,8 +321,7 @@ static inline snd_pcm_format_t params_format(const struct snd_pcm_hw_params *p)
static inline snd_pcm_subformat_t
params_subformat(const struct snd_pcm_hw_params *p)
{
- return (__force snd_pcm_subformat_t)snd_mask_min(hw_param_mask_c(p,
- SNDRV_PCM_HW_PARAM_SUBFORMAT));
+ return snd_mask_min(hw_param_mask_c(p, SNDRV_PCM_HW_PARAM_SUBFORMAT));
}
/**
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index bfedf571e021..41c2cab7a52c 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -211,11 +211,9 @@ static const char * const snd_pcm_format_names[] = {
*/
const char *snd_pcm_format_name(snd_pcm_format_t format)
{
- unsigned int format_num = (__force unsigned int)format;
-
- if (format_num >= ARRAY_SIZE(snd_pcm_format_names) || !snd_pcm_format_names[format_num])
+ if (format >= ARRAY_SIZE(snd_pcm_format_names) || !snd_pcm_format_names[format])
return "Unknown";
- return snd_pcm_format_names[format_num];
+ return snd_pcm_format_names[format];
}
EXPORT_SYMBOL_GPL(snd_pcm_format_name);
@@ -275,12 +273,12 @@ static const char *snd_pcm_stream_name(int stream)
static const char *snd_pcm_access_name(snd_pcm_access_t access)
{
- return snd_pcm_access_names[(__force int)access];
+ return snd_pcm_access_names[access];
}
static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
{
- return snd_pcm_subformat_names[(__force int)subformat];
+ return snd_pcm_subformat_names[subformat];
}
static const char *snd_pcm_tstamp_mode_name(int mode)
@@ -290,7 +288,7 @@ static const char *snd_pcm_tstamp_mode_name(int mode)
static const char *snd_pcm_state_name(snd_pcm_state_t state)
{
- return snd_pcm_state_names[(__force int)state];
+ return snd_pcm_state_names[state];
}
#if IS_ENABLED(CONFIG_SND_PCM_OSS)
diff --git a/sound/core/pcm_misc.c b/sound/core/pcm_misc.c
index 180b6b64a448..13de3b02aa34 100644
--- a/sound/core/pcm_misc.c
+++ b/sound/core/pcm_misc.c
@@ -24,15 +24,12 @@ struct pcm_format_data {
unsigned char silence[8]; /* silence data to fill */
};
-/* we do lots of calculations on snd_pcm_format_t; shut up sparse */
-#define INT __force int
-
static bool valid_format(snd_pcm_format_t format)
{
- return (INT)format >= 0 && (INT)format <= (INT)SNDRV_PCM_FORMAT_LAST;
+ return format >= 0 && format <= SNDRV_PCM_FORMAT_LAST;
}
-static const struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = {
+static const struct pcm_format_data pcm_formats[SNDRV_PCM_FORMAT_LAST+1] = {
[SNDRV_PCM_FORMAT_S8] = {
.width = 8, .phys = 8, .le = -1, .signd = 1,
.silence = {},
@@ -251,7 +248,7 @@ int snd_pcm_format_signed(snd_pcm_format_t format)
int val;
if (!valid_format(format))
return -EINVAL;
- val = pcm_formats[(INT)format].signd;
+ val = pcm_formats[format].signd;
if (val < 0)
return -EINVAL;
return val;
@@ -300,7 +297,7 @@ int snd_pcm_format_little_endian(snd_pcm_format_t format)
int val;
if (!valid_format(format))
return -EINVAL;
- val = pcm_formats[(INT)format].le;
+ val = pcm_formats[format].le;
if (val < 0)
return -EINVAL;
return val;
@@ -337,7 +334,7 @@ int snd_pcm_format_width(snd_pcm_format_t format)
int val;
if (!valid_format(format))
return -EINVAL;
- val = pcm_formats[(INT)format].width;
+ val = pcm_formats[format].width;
if (!val)
return -EINVAL;
return val;
@@ -356,7 +353,7 @@ int snd_pcm_format_physical_width(snd_pcm_format_t format)
int val;
if (!valid_format(format))
return -EINVAL;
- val = pcm_formats[(INT)format].phys;
+ val = pcm_formats[format].phys;
if (!val)
return -EINVAL;
return val;
@@ -390,9 +387,9 @@ const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format)
{
if (!valid_format(format))
return NULL;
- if (! pcm_formats[(INT)format].phys)
+ if (! pcm_formats[format].phys)
return NULL;
- return pcm_formats[(INT)format].silence;
+ return pcm_formats[format].silence;
}
EXPORT_SYMBOL(snd_pcm_format_silence_64);
@@ -416,12 +413,12 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
return -EINVAL;
if (samples == 0)
return 0;
- width = pcm_formats[(INT)format].phys; /* physical width */
+ width = pcm_formats[format].phys; /* physical width */
if (!width)
return -EINVAL;
- pat = pcm_formats[(INT)format].silence;
+ pat = pcm_formats[format].silence;
/* signed or 1 byte data */
- if (pcm_formats[(INT)format].signd == 1 || width <= 8) {
+ if (pcm_formats[format].signd == 1 || width <= 8) {
unsigned int bytes = samples * width / 8;
memset(data, *pat, bytes);
return 0;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index f44dc334aac6..4a5057e7629d 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -257,7 +257,7 @@ int snd_pcm_info_user(struct snd_pcm_substream *substream,
}
/* macro for simplified cast */
-#define PARAM_MASK_BIT(b) (1U << (__force int)(b))
+#define PARAM_MASK_BIT(b) (1U << (b))
static bool hw_support_mmap(struct snd_pcm_substream *substream)
{
@@ -489,7 +489,7 @@ static int fixup_unreferenced_params(struct snd_pcm_substream *substream,
params->msbits = snd_interval_value(i);
m = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT);
if (snd_mask_single(m)) {
- snd_pcm_format_t format = (__force snd_pcm_format_t)snd_mask_min(m);
+ snd_pcm_format_t format = snd_mask_min(m);
params->msbits = snd_pcm_format_width(format);
}
}
@@ -497,13 +497,13 @@ static int fixup_unreferenced_params(struct snd_pcm_substream *substream,
if (params->msbits) {
m = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT);
if (snd_mask_single(m)) {
- snd_pcm_format_t format = (__force snd_pcm_format_t)snd_mask_min(m);
+ snd_pcm_format_t format = snd_mask_min(m);
if (snd_pcm_format_linear(format) &&
snd_pcm_format_width(format) != params->msbits) {
m_rw = hw_param_mask(params, SNDRV_PCM_HW_PARAM_SUBFORMAT);
snd_mask_reset(m_rw,
- (__force unsigned)SNDRV_PCM_SUBFORMAT_MSBITS_MAX);
+ SNDRV_PCM_SUBFORMAT_MSBITS_MAX);
if (snd_mask_empty(m_rw))
return -EINVAL;
}
@@ -1252,7 +1252,7 @@ static void snd_pcm_trigger_tstamp(struct snd_pcm_substream *substream)
runtime->trigger_master = NULL;
}
-#define ACTION_ARG_IGNORE (__force snd_pcm_state_t)0
+#define ACTION_ARG_IGNORE 0
struct action_ops {
int (*pre_action)(struct snd_pcm_substream *substream,
@@ -1635,7 +1635,7 @@ EXPORT_SYMBOL_GPL(snd_pcm_stop_xrun);
/*
* pause callbacks: pass boolean (to start pause or resume) as state argument
*/
-#define pause_pushed(state) (__force bool)(state)
+#define pause_pushed(state) (bool)(state)
static int snd_pcm_pre_pause(struct snd_pcm_substream *substream,
snd_pcm_state_t state)
@@ -1707,14 +1707,14 @@ static const struct action_ops snd_pcm_action_pause = {
static int snd_pcm_pause(struct snd_pcm_substream *substream, bool push)
{
return snd_pcm_action(&snd_pcm_action_pause, substream,
- (__force snd_pcm_state_t)push);
+ (snd_pcm_state_t)push);
}
static int snd_pcm_pause_lock_irq(struct snd_pcm_substream *substream,
bool push)
{
return snd_pcm_action_lock_irq(&snd_pcm_action_pause, substream,
- (__force snd_pcm_state_t)push);
+ (snd_pcm_state_t)push);
}
#ifdef CONFIG_PM
@@ -1982,7 +1982,7 @@ static int snd_pcm_pre_prepare(struct snd_pcm_substream *substream,
snd_pcm_state_t state)
{
snd_pcm_state_t cur_state = snd_pcm_get_state(substream);
- int f_flags = (__force int)state;
+ int f_flags = state;
if (cur_state == SNDRV_PCM_STATE_OPEN ||
cur_state == SNDRV_PCM_STATE_DISCONNECTED)
@@ -2050,7 +2050,7 @@ static int snd_pcm_prepare(struct snd_pcm_substream *substream,
return snd_pcm_action_nonatomic(&snd_pcm_action_prepare,
substream,
- (__force snd_pcm_state_t)f_flags);
+ (snd_pcm_state_t)f_flags);
}
/*
@@ -2461,7 +2461,7 @@ static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params *params,
if (bits <= 0)
continue; /* ignore invalid formats */
if ((unsigned)bits < i->min || (unsigned)bits > i->max)
- snd_mask_reset(&m, (__force unsigned)k);
+ snd_mask_reset(&m, k);
}
return snd_mask_refine(mask, &m);
}
@@ -2543,16 +2543,16 @@ static int snd_pcm_hw_rule_subformats(struct snd_pcm_hw_params *params,
snd_mask_none(&m);
/* All PCMs support at least the default STD subformat. */
- snd_mask_set(&m, (__force unsigned)SNDRV_PCM_SUBFORMAT_STD);
+ snd_mask_set(&m, SNDRV_PCM_SUBFORMAT_STD);
pcm_for_each_format(f) {
- if (!snd_mask_test(fmask, (__force unsigned)f))
+ if (!snd_mask_test(fmask, f))
continue;
if (f == SNDRV_PCM_FORMAT_S32_LE && *subformats)
m.bits[0] |= *subformats;
else if (snd_pcm_format_linear(f))
- snd_mask_set(&m, (__force unsigned)SNDRV_PCM_SUBFORMAT_MSBITS_MAX);
+ snd_mask_set(&m, SNDRV_PCM_SUBFORMAT_MSBITS_MAX);
}
return snd_mask_refine(sfmask, &m);
--
2.55.0
next prev parent reply other threads:[~2026-08-12 6:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 6:04 [PATCH 00/14] ALSA: Drop __bitwise and __force prefix Takashi Iwai
2026-08-12 6:04 ` [PATCH 01/14] ALSA: uapi: " Takashi Iwai
2026-08-12 6:04 ` Takashi Iwai [this message]
2026-08-12 6:04 ` [PATCH 03/14] ALSA: pcm: Avoid macros for SNDRV_PCM_FMTBIT and SNDRV_PCM_SUBFMTBIT Takashi Iwai
2026-08-12 6:04 ` [PATCH 04/14] ALSA: control: Drop __force casts Takashi Iwai
2026-08-12 6:04 ` [PATCH 05/14] ALSA: oss: " Takashi Iwai
2026-08-12 6:04 ` [PATCH 06/14] ALSA: kunit: " Takashi Iwai
2026-08-12 6:04 ` [PATCH 07/14] ALSA: aloop: " Takashi Iwai
2026-08-12 6:04 ` [PATCH 08/14] ALSA: hda: " Takashi Iwai
2026-08-12 6:04 ` [PATCH 09/14] ALSA: asihpi: Drop __force cast Takashi Iwai
2026-08-12 6:04 ` [PATCH 10/14] ALSA: emu10k1: Drop __force casts Takashi Iwai
2026-08-12 6:04 ` [PATCH 11/14] ASoC: fsl: " Takashi Iwai
2026-08-12 9:41 ` Shengjiu Wang
2026-08-12 12:49 ` Mark Brown
2026-08-12 6:04 ` [PATCH 12/14] ASoC: Intel: avs: Drop __force cast Takashi Iwai
2026-08-12 7:12 ` Cezary Rojewski
2026-08-12 14:04 ` Mark Brown
2026-08-12 6:04 ` [PATCH 13/14] ASoC: mediatek: Drop __force casts Takashi Iwai
2026-08-12 14:06 ` Mark Brown
2026-08-12 6:04 ` [PATCH 14/14] ASoC: meson: Drop __force cast Takashi Iwai
2026-08-12 14:07 ` Mark Brown
2026-08-12 7:27 ` [PATCH 00/14] ALSA: Drop __bitwise and __force prefix Cezary Rojewski
2026-08-12 7:34 ` 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=20260812060557.80445-3-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-sound@vger.kernel.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