ALSA: hda: Use min() to simplify snd_hda_get_devices()
PATCH 1/2 ALSA: hda: Use min() to simplify snd_hda_get_devices()
Use min() to simplify snd_hda_get_devices() and improve its readability.
Change the function parameter 'max_devices' from 'int' to 'unsigned int' to avoid a min() signedness error. Update all related local variables and the function's return type to 'unsigned int' accordingly.
No functional changes intended.
--- include/sound/hda_codec.h | 4 ++-- sound/hda/common/codec.c | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-)
include/sound/hda_codec.h +2 -2
@@ -360,8 +360,8 @@ int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,int snd_hda_get_conn_index (struct hda_codec *codec,hda_nid_t mux,hda_nid_t nid,int recursive);unsigned int snd_hda_get_num_devices (struct hda_codec *codec,hda_nid_t nid); -int snd_hda_get_devices (struct hda_codec *codec,hda_nid_t nid, -u8 *dev_list,int max_devices); +unsigned int snd_hda_get_devices (struct hda_codec *codec,hda_nid_t nid, +u8 *dev_list,unsigned int max_devices);int snd_hda_get_dev_select (struct hda_codec *codec,hda_nid_t nid);int snd_hda_set_dev_select (struct hda_codec *codec,hda_nid_t nid,int dev_id);
sound/hda/common/codec.c +5 -6
@@ -8,6 +8,7 @@#include <linux/init.h> #include <linux/delay.h> #include <linux/slab.h> +#include <linux/minmax.h> #include <linux/mutex.h> #include <linux/module.h> #include <linux/pm.h>
@@ -323,18 +324,16 @@ EXPORT_SYMBOL_GPL(snd_hda_get_num_devices);* Copy the device list. This info is dynamic and so not cached. * Currently called only from hda_proc.c, so not exported. */ -int snd_hda_get_devices (struct hda_codec *codec,hda_nid_t nid, -u8 *dev_list,int max_devices) +unsigned int snd_hda_get_devices (struct hda_codec *codec,hda_nid_t nid, +u8 *dev_list,unsigned int max_devices) { -unsigned int parm; -int i, dev_len, devices; +unsigned int parm, i, dev_len, devices; parm =snd_hda_get_num_devices (codec, nid);if (!parm)/* not multi-stream capable */ return 0 ; - dev_len = parm +1 ; - dev_len = dev_len < max_devices ? dev_len : max_devices; + dev_len =min (parm +1 , max_devices); devices =0 ;while (devices < dev_len) {
Signature · 1 line
2.50.1
PATCH 2/2 ALSA: hda: Improve local variable data type in print_device_list()
Use 'unsigned int' instead of 'int' for the local variable 'devlist_len' because snd_hda_get_devices() returns an 'unsigned int' and the length cannot be negative. Update the print format specifier and the if condition accordingly.
Reformat calling snd_hda_codec_read() to fit in a single line while we're at it.
--- sound/hda/common/proc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
sound/hda/common/proc.c +4 -5
@@ -716,16 +716,15 @@ static void print_device_list(struct snd_info_buffer *buffer, {int i, curr =-1 ;u8 dev_list[AC_MAX_DEV_LIST_LEN ]; -int devlist_len; +unsigned int devlist_len; devlist_len =snd_hda_get_devices (codec, nid, dev_list,AC_MAX_DEV_LIST_LEN ); -snd_iprintf (buffer," Devices: %d\n" , devlist_len); -if (devlist_len <=0 ) +snd_iprintf (buffer," Devices: %u\n" , devlist_len); +if (devlist_len ==0 )return ; - curr =snd_hda_codec_read (codec, nid,0 , -AC_VERB_GET_DEVICE_SEL ,0 ); + curr =snd_hda_codec_read (codec, nid,0 ,AC_VERB_GET_DEVICE_SEL ,0 );for (i =0 ; i < devlist_len; i++) {if (i == curr)
Signature · 1 line
2.50.1
Takashi Iwai
AppliedQuoted 10 lines · Thorsten Blum
Use
min()to simplifysnd_hda_get_devices()and improve its readability.Change the function parameter '
max_devices' from 'int' to 'unsigned int' to avoid amin()signedness error. Update all related local variables and the function's return type to 'unsigned int' accordingly.No functional changes intended.
Signed-off-by Thorsten Blum <[email protected]>
Applied both patches now. Thanks.
Takashi