* [PATCH] ALSA/ASoC: replace ternary operator with min()
@ 2022-10-25 14:56 wangkailong
2022-10-25 17:01 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: wangkailong @ 2022-10-25 14:56 UTC (permalink / raw)
To: perex, tiwai, lgirdwood, broonie, motolav, cezary.rojewski,
mkumard, pierre-louis.bossart, kai.vehmanen, peter.ujfalusi
Cc: alsa-devel, linux-kernel
Fix the following coccicheck warning:
sound/soc/soc-ops.c:817: WARNING opportunity for min()
sound/core/vmaster.c:73: WARNING opportunity for min()
sound/pci/hda/hda_codec.c:337: WARNING opportunity for min()
sound/pci/ctxfi/ctatc.c:448: WARNING opportunity for min()
sound/pci/ctxfi/ctatc.c:387: WARNING opportunity for min()
Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
---
sound/core/vmaster.c | 2 +-
sound/pci/ctxfi/ctatc.c | 4 ++--
sound/pci/hda/hda_codec.c | 2 +-
sound/soc/soc-ops.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index d0f11f37889b..704a09f4bfd6 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -70,7 +70,7 @@ static int follower_update(struct link_follower *follower)
follower->vals[ch] = uctl->value.integer.value[ch];
error:
kfree(uctl);
- return err < 0 ? err : 0;
+ return min(err, 0);
}
/* get the follower ctl info and save the initial values */
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index fbdb8a3d5b8e..9fea50b72cfb 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -384,7 +384,7 @@ static int atc_pcm_playback_start(struct ct_atc *atc, struct ct_atc_pcm *apcm)
apcm->started = 1;
max_cisz = src->multi * src->rsc.msr;
- max_cisz = 0x80 * (max_cisz < 8 ? max_cisz : 8);
+ max_cisz = 0x80 * min(max_cisz, 8);
src->ops->set_sa(src, apcm->vm_block->addr);
src->ops->set_la(src, apcm->vm_block->addr + apcm->vm_block->size);
@@ -445,7 +445,7 @@ atc_pcm_playback_position(struct ct_atc *atc, struct ct_atc_pcm *apcm)
size = apcm->vm_block->size;
max_cisz = src->multi * src->rsc.msr;
- max_cisz = 128 * (max_cisz < 8 ? max_cisz : 8);
+ max_cisz = 128 * min(max_cisz, 8);
return (position + size - max_cisz - apcm->vm_block->addr) % size;
}
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index b4d1e658c556..c195f99bd8d5 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -334,7 +334,7 @@ int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
return 0;
dev_len = parm + 1;
- dev_len = dev_len < max_devices ? dev_len : max_devices;
+ dev_len = min(dev_len, max_devices);
devices = 0;
while (devices < dev_len) {
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index bd88de056358..d71d10055ed7 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -814,7 +814,7 @@ int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
unsigned int size, unsigned int __user *tlv)
{
struct soc_bytes_ext *params = (void *)kcontrol->private_value;
- unsigned int count = size < params->max ? size : params->max;
+ unsigned int count = min_t(unsigned int, size, params->max);
int ret = -ENXIO;
switch (op_flag) {
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA/ASoC: replace ternary operator with min()
2022-10-25 14:56 [PATCH] ALSA/ASoC: replace ternary operator with min() wangkailong
@ 2022-10-25 17:01 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2022-10-25 17:01 UTC (permalink / raw)
To: wangkailong
Cc: perex, tiwai, lgirdwood, motolav, cezary.rojewski, mkumard,
pierre-louis.bossart, kai.vehmanen, peter.ujfalusi, alsa-devel,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 400 bytes --]
On Tue, Oct 25, 2022 at 10:56:11PM +0800, wangkailong@jari.cn wrote:
> Fix the following coccicheck warning:
>
> sound/soc/soc-ops.c:817: WARNING opportunity for min()
> kfree(uctl);
> - return err < 0 ? err : 0;
> + return min(err, 0);
I don't think this is a good warning, while I'm no big fan of the
ternery operator the new code is less clear about the intent than the
old code.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 484 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA/ASoC: replace ternary operator with min()
@ 2022-10-25 17:01 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2022-10-25 17:01 UTC (permalink / raw)
To: wangkailong
Cc: alsa-devel, pierre-louis.bossart, motolav, kai.vehmanen,
linux-kernel, cezary.rojewski, lgirdwood, tiwai, peter.ujfalusi,
mkumard
[-- Attachment #1: Type: text/plain, Size: 400 bytes --]
On Tue, Oct 25, 2022 at 10:56:11PM +0800, wangkailong@jari.cn wrote:
> Fix the following coccicheck warning:
>
> sound/soc/soc-ops.c:817: WARNING opportunity for min()
> kfree(uctl);
> - return err < 0 ? err : 0;
> + return min(err, 0);
I don't think this is a good warning, while I'm no big fan of the
ternery operator the new code is less clear about the intent than the
old code.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 484 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA/ASoC: replace ternary operator with min()
2022-10-25 17:01 ` Mark Brown
@ 2022-10-26 5:28 ` Takashi Iwai
-1 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2022-10-26 5:28 UTC (permalink / raw)
To: Mark Brown
Cc: wangkailong, perex, tiwai, lgirdwood, motolav, cezary.rojewski,
mkumard, pierre-louis.bossart, kai.vehmanen, peter.ujfalusi,
alsa-devel, linux-kernel
On Tue, 25 Oct 2022 19:01:32 +0200,
Mark Brown wrote:
>
> On Tue, Oct 25, 2022 at 10:56:11PM +0800, wangkailong@jari.cn wrote:
> > Fix the following coccicheck warning:
> >
> > sound/soc/soc-ops.c:817: WARNING opportunity for min()
>
> > kfree(uctl);
> > - return err < 0 ? err : 0;
> > + return min(err, 0);
>
> I don't think this is a good warning, while I'm no big fan of the
> ternery operator the new code is less clear about the intent than the
> old code.
Agreed. That use of ternery is a standard idiom.
If we have to eliminate the use of ternery inevitably, it'd be better
to introduce a new macro for clarity instead.
thanks,
Takashi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA/ASoC: replace ternary operator with min()
@ 2022-10-26 5:28 ` Takashi Iwai
0 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2022-10-26 5:28 UTC (permalink / raw)
To: Mark Brown
Cc: alsa-devel, pierre-louis.bossart, motolav, kai.vehmanen,
linux-kernel, cezary.rojewski, lgirdwood, tiwai, wangkailong,
peter.ujfalusi, mkumard
On Tue, 25 Oct 2022 19:01:32 +0200,
Mark Brown wrote:
>
> On Tue, Oct 25, 2022 at 10:56:11PM +0800, wangkailong@jari.cn wrote:
> > Fix the following coccicheck warning:
> >
> > sound/soc/soc-ops.c:817: WARNING opportunity for min()
>
> > kfree(uctl);
> > - return err < 0 ? err : 0;
> > + return min(err, 0);
>
> I don't think this is a good warning, while I'm no big fan of the
> ternery operator the new code is less clear about the intent than the
> old code.
Agreed. That use of ternery is a standard idiom.
If we have to eliminate the use of ternery inevitably, it'd be better
to introduce a new macro for clarity instead.
thanks,
Takashi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA/ASoC: replace ternary operator with min()
2022-10-26 5:28 ` Takashi Iwai
@ 2022-10-26 12:25 ` Mark Brown
-1 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2022-10-26 12:25 UTC (permalink / raw)
To: Takashi Iwai
Cc: wangkailong, perex, tiwai, lgirdwood, motolav, cezary.rojewski,
mkumard, pierre-louis.bossart, kai.vehmanen, peter.ujfalusi,
alsa-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]
On Wed, Oct 26, 2022 at 07:28:26AM +0200, Takashi Iwai wrote:
> Mark Brown wrote:
> > On Tue, Oct 25, 2022 at 10:56:11PM +0800, wangkailong@jari.cn wrote:
> > > sound/soc/soc-ops.c:817: WARNING opportunity for min()
> > > kfree(uctl);
> > > - return err < 0 ? err : 0;
> > > + return min(err, 0);
> > I don't think this is a good warning, while I'm no big fan of the
> > ternery operator the new code is less clear about the intent than the
> > old code.
> Agreed. That use of ternery is a standard idiom.
> If we have to eliminate the use of ternery inevitably, it'd be better
> to introduce a new macro for clarity instead.
It looks like it's more about identifying a pattern that could be min()
but not being able to detect the semantics of why we're comparing
numbers.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA/ASoC: replace ternary operator with min()
@ 2022-10-26 12:25 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2022-10-26 12:25 UTC (permalink / raw)
To: Takashi Iwai
Cc: alsa-devel, pierre-louis.bossart, motolav, kai.vehmanen,
linux-kernel, cezary.rojewski, lgirdwood, tiwai, wangkailong,
peter.ujfalusi, mkumard
[-- Attachment #1: Type: text/plain, Size: 782 bytes --]
On Wed, Oct 26, 2022 at 07:28:26AM +0200, Takashi Iwai wrote:
> Mark Brown wrote:
> > On Tue, Oct 25, 2022 at 10:56:11PM +0800, wangkailong@jari.cn wrote:
> > > sound/soc/soc-ops.c:817: WARNING opportunity for min()
> > > kfree(uctl);
> > > - return err < 0 ? err : 0;
> > > + return min(err, 0);
> > I don't think this is a good warning, while I'm no big fan of the
> > ternery operator the new code is less clear about the intent than the
> > old code.
> Agreed. That use of ternery is a standard idiom.
> If we have to eliminate the use of ternery inevitably, it'd be better
> to introduce a new macro for clarity instead.
It looks like it's more about identifying a pattern that could be min()
but not being able to detect the semantics of why we're comparing
numbers.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-10-26 12:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25 14:56 [PATCH] ALSA/ASoC: replace ternary operator with min() wangkailong
2022-10-25 17:01 ` Mark Brown
2022-10-25 17:01 ` Mark Brown
2022-10-26 5:28 ` Takashi Iwai
2022-10-26 5:28 ` Takashi Iwai
2022-10-26 12:25 ` Mark Brown
2022-10-26 12:25 ` Mark Brown
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.