]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: hda: Use min() to simplify snd_hda_get_devices()
authorThorsten Blum <thorsten.blum@linux.dev>
Wed, 13 Aug 2025 20:55:02 +0000 (22:55 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 14 Aug 2025 06:39:54 +0000 (08:39 +0200)
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.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20250813205507.215658-2-thorsten.blum@linux.dev
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/hda_codec.h
sound/hda/common/codec.c

index ddc9c392f93f6db45209db10bffdb44efe8b3474..006d4e4a8195d0ee6b0ecc62fc93561f40d23c66 100644 (file)
@@ -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);
 
index cab479111603dcdffb64a5251b162bcedb538af8..7a72d4c7ae914a25209207a10a03a5ae560eb1b0 100644 (file)
@@ -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) {