ALSA/ASoC: replace ternary operator with min()
PATCH 1/1 ALSA/ASoC: replace ternary operator with min()
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()
--- 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(-)
sound/core/vmaster.c +1 -1
@@ -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 */
sound/pci/ctxfi/ctatc.c +2 -2
@@ -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; }
sound/pci/hda/hda_codec.c +1 -1
@@ -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) {
sound/soc/soc-ops.c +1 -1
@@ -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) {
Signature · 1 line
2.25.1
Mark Brown
maintainersound/core/vmaster.c static int follower_update(struct link_follower *follower) · line 73
Quoted 7 lines · On Tue, Oct 25, 2022 at 10:56:11PM +0800, [email protected] wrote:
Fix the following coccicheck warning:
sound/soc/soc-ops.c:817: WARNING opportunity formin()sound/core/vmaster.c +1
-1kfree (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.
Quoted 6 lines · Mark Brown
Quoted 3 lines · On Tue, Oct 25, 2022 at 10:56:11PM +0800, [email protected] wrote:
Fix the following coccicheck warning:
sound/soc/soc-ops.c:817: WARNING opportunity formin()
Quoted 7 lines
sound/core/vmaster.c static int follower_update(struct link_follower *follower) · line 73
Quoted 3 lines
sound/core/vmaster.c +1
-1kfree (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
Mark Brown
maintainerQuoted 13 lines · Takashi Iwai
Quoted 11 lines · Mark Brown
sound/core/vmaster.c static int follower_update(struct link_follower *follower) · line 73
Quoted 5 lines · On Tue, Oct 25, 2022 at 10:56:11PM +0800, [email protected] wrote:
sound/soc/soc-ops.c:817: WARNING opportunity formin()sound/core/vmaster.c +1
-1kfree (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.
Quoted 4 lines
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.