Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: usb-audio: Constify audioformat pointer references

The audioformat is referred in many places but most of usages are
read-only. Let's add const prefix in the possible places.

Tested-by: Keith Milner <kamilner@superlative.org>
Tested-by: Dylan Robinson <dylan_robinson@motu.com>
Link: https://lore.kernel.org/r/20201123085347.19667-28-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+39 -38
+2 -2
sound/usb/card.h
··· 120 120 bool need_setup; /* (re-)need for configure? */ 121 121 122 122 /* for hw constraints */ 123 - struct audioformat *cur_audiofmt; 123 + const struct audioformat *cur_audiofmt; 124 124 unsigned int cur_rate; 125 125 snd_pcm_format_t cur_format; 126 126 unsigned int cur_channels; ··· 142 142 int direction; /* playback or capture */ 143 143 int interface; /* current interface */ 144 144 int endpoint; /* assigned endpoint */ 145 - struct audioformat *cur_audiofmt; /* current audioformat pointer (for hw_params callback) */ 145 + const struct audioformat *cur_audiofmt; /* current audioformat pointer (for hw_params callback) */ 146 146 struct snd_usb_power_domain *str_pd; /* UAC3 Power Domain for streaming path */ 147 147 snd_pcm_format_t pcm_format; /* current audio format (for hw_params callback) */ 148 148 unsigned int channels; /* current number of channels (for hw_params callback) */
+8 -8
sound/usb/clock.c
··· 152 152 } 153 153 154 154 static bool uac_clock_source_is_valid_quirk(struct snd_usb_audio *chip, 155 - struct audioformat *fmt, 155 + const struct audioformat *fmt, 156 156 int source_id) 157 157 { 158 158 bool ret = false; ··· 215 215 } 216 216 217 217 static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, 218 - struct audioformat *fmt, 218 + const struct audioformat *fmt, 219 219 int source_id) 220 220 { 221 221 int err; ··· 264 264 } 265 265 266 266 static int __uac_clock_find_source(struct snd_usb_audio *chip, 267 - struct audioformat *fmt, int entity_id, 267 + const struct audioformat *fmt, int entity_id, 268 268 unsigned long *visited, bool validate) 269 269 { 270 270 struct uac_clock_source_descriptor *source; ··· 358 358 } 359 359 360 360 static int __uac3_clock_find_source(struct snd_usb_audio *chip, 361 - struct audioformat *fmt, int entity_id, 361 + const struct audioformat *fmt, int entity_id, 362 362 unsigned long *visited, bool validate) 363 363 { 364 364 struct uac3_clock_source_descriptor *source; ··· 464 464 * Returns the clock source UnitID (>=0) on success, or an error. 465 465 */ 466 466 int snd_usb_clock_find_source(struct snd_usb_audio *chip, 467 - struct audioformat *fmt, bool validate) 467 + const struct audioformat *fmt, bool validate) 468 468 { 469 469 DECLARE_BITMAP(visited, 256); 470 470 memset(visited, 0, sizeof(visited)); ··· 482 482 } 483 483 484 484 static int set_sample_rate_v1(struct snd_usb_audio *chip, 485 - struct audioformat *fmt, int rate) 485 + const struct audioformat *fmt, int rate) 486 486 { 487 487 struct usb_device *dev = chip->dev; 488 488 struct usb_host_interface *alts; ··· 611 611 } 612 612 613 613 static int set_sample_rate_v2v3(struct snd_usb_audio *chip, 614 - struct audioformat *fmt, int rate) 614 + const struct audioformat *fmt, int rate) 615 615 { 616 616 int cur_rate, prev_rate; 617 617 int clock; ··· 663 663 } 664 664 665 665 int snd_usb_init_sample_rate(struct snd_usb_audio *chip, 666 - struct audioformat *fmt, int rate) 666 + const struct audioformat *fmt, int rate) 667 667 { 668 668 usb_audio_dbg(chip, "%d:%d Set sample rate %d, clock %d\n", 669 669 fmt->iface, fmt->altsetting, rate, fmt->clock);
+2 -2
sound/usb/clock.h
··· 3 3 #define __USBAUDIO_CLOCK_H 4 4 5 5 int snd_usb_init_sample_rate(struct snd_usb_audio *chip, 6 - struct audioformat *fmt, int rate); 6 + const struct audioformat *fmt, int rate); 7 7 8 8 int snd_usb_clock_find_source(struct snd_usb_audio *chip, 9 - struct audioformat *fmt, bool validate); 9 + const struct audioformat *fmt, bool validate); 10 10 11 11 int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio *chip, 12 12 const struct audioformat *fmt,
+1 -1
sound/usb/endpoint.c
··· 623 623 */ 624 624 struct snd_usb_endpoint * 625 625 snd_usb_endpoint_open(struct snd_usb_audio *chip, 626 - struct audioformat *fp, 626 + const struct audioformat *fp, 627 627 const struct snd_pcm_hw_params *params, 628 628 bool is_sync_ep) 629 629 {
+1 -1
sound/usb/endpoint.h
··· 12 12 13 13 struct snd_usb_endpoint * 14 14 snd_usb_endpoint_open(struct snd_usb_audio *chip, 15 - struct audioformat *fp, 15 + const struct audioformat *fp, 16 16 const struct snd_pcm_hw_params *params, 17 17 bool is_sync_ep); 18 18 void snd_usb_endpoint_close(struct snd_usb_audio *chip,
+16 -16
sound/usb/pcm.c
··· 80 80 /* 81 81 * find a matching audio format 82 82 */ 83 - static struct audioformat * 83 + static const struct audioformat * 84 84 find_format(struct list_head *fmt_list_head, snd_pcm_format_t format, 85 85 unsigned int rate, unsigned int channels, bool strict_match, 86 86 struct snd_usb_substream *subs) 87 87 { 88 - struct audioformat *fp; 89 - struct audioformat *found = NULL; 88 + const struct audioformat *fp; 89 + const struct audioformat *found = NULL; 90 90 int cur_attr = 0, attr; 91 91 92 92 list_for_each_entry(fp, fmt_list_head, list) { ··· 141 141 return found; 142 142 } 143 143 144 - static struct audioformat * 144 + static const struct audioformat * 145 145 find_substream_format(struct snd_usb_substream *subs, 146 146 const struct snd_pcm_hw_params *params) 147 147 { ··· 182 182 * initialize the pitch control and sample rate 183 183 */ 184 184 int snd_usb_init_pitch(struct snd_usb_audio *chip, 185 - struct audioformat *fmt) 185 + const struct audioformat *fmt) 186 186 { 187 187 int err; 188 188 ··· 641 641 return NULL; 642 642 } 643 643 644 - static struct audioformat * 644 + static const struct audioformat * 645 645 find_implicit_fb_sync_format(struct snd_usb_audio *chip, 646 646 const struct audioformat *target, 647 647 const struct snd_pcm_hw_params *params, 648 648 int stream) 649 649 { 650 650 struct snd_usb_substream *subs; 651 - struct audioformat *fp, *sync_fmt; 651 + const struct audioformat *fp, *sync_fmt; 652 652 int score, high_score; 653 653 654 654 subs = find_matching_substream(chip, stream, target->sync_ep, ··· 726 726 { 727 727 struct snd_usb_substream *subs = substream->runtime->private_data; 728 728 struct snd_usb_audio *chip = subs->stream->chip; 729 - struct audioformat *fmt; 730 - struct audioformat *sync_fmt; 729 + const struct audioformat *fmt; 730 + const struct audioformat *sync_fmt; 731 731 int ret; 732 732 733 733 ret = snd_media_start_pipeline(subs); ··· 918 918 919 919 static int hw_check_valid_format(struct snd_usb_substream *subs, 920 920 struct snd_pcm_hw_params *params, 921 - struct audioformat *fp) 921 + const struct audioformat *fp) 922 922 { 923 923 struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 924 924 struct snd_interval *ct = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); ··· 995 995 struct snd_pcm_hw_rule *rule) 996 996 { 997 997 struct snd_usb_substream *subs = rule->private; 998 - struct audioformat *fp; 998 + const struct audioformat *fp; 999 999 struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); 1000 1000 unsigned int rmin, rmax, r; 1001 1001 int i; ··· 1028 1028 struct snd_pcm_hw_rule *rule) 1029 1029 { 1030 1030 struct snd_usb_substream *subs = rule->private; 1031 - struct audioformat *fp; 1031 + const struct audioformat *fp; 1032 1032 struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); 1033 1033 unsigned int rmin, rmax; 1034 1034 ··· 1049 1049 struct snd_pcm_hw_rule *rule) 1050 1050 { 1051 1051 struct snd_usb_substream *subs = rule->private; 1052 - struct audioformat *fp; 1052 + const struct audioformat *fp; 1053 1053 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 1054 1054 u64 fbits; 1055 1055 u32 oldbits[2]; ··· 1080 1080 struct snd_pcm_hw_rule *rule) 1081 1081 { 1082 1082 struct snd_usb_substream *subs = rule->private; 1083 - struct audioformat *fp; 1083 + const struct audioformat *fp; 1084 1084 struct snd_interval *it; 1085 1085 unsigned char min_datainterval; 1086 1086 unsigned int pmin; ··· 1109 1109 { 1110 1110 struct snd_usb_audio *chip = subs->stream->chip; 1111 1111 struct snd_usb_endpoint *ep; 1112 - struct audioformat *fp; 1112 + const struct audioformat *fp; 1113 1113 int err; 1114 1114 1115 1115 list_for_each_entry(fp, &subs->fmt_list, list) { ··· 1170 1170 static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs) 1171 1171 { 1172 1172 struct snd_usb_audio *chip = subs->stream->chip; 1173 - struct audioformat *fp; 1173 + const struct audioformat *fp; 1174 1174 unsigned int pt, ptmin; 1175 1175 int param_period_time_if_needed = -1; 1176 1176 int err;
+1 -1
sound/usb/pcm.h
··· 10 10 int snd_usb_pcm_resume(struct snd_usb_stream *as); 11 11 12 12 int snd_usb_init_pitch(struct snd_usb_audio *chip, 13 - struct audioformat *fmt); 13 + const struct audioformat *fmt); 14 14 void snd_usb_preallocate_buffer(struct snd_usb_substream *subs); 15 15 16 16 int snd_usb_audioformat_set_sync_ep(struct snd_usb_audio *chip,
+5 -4
sound/usb/quirks.c
··· 1375 1375 /* 1376 1376 * check if the device uses big-endian samples 1377 1377 */ 1378 - int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp) 1378 + int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, 1379 + const struct audioformat *fp) 1379 1380 { 1380 1381 /* it depends on altsetting whether the device is big-endian or not */ 1381 1382 switch (chip->usb_id) { ··· 1415 1414 }; 1416 1415 1417 1416 static void set_format_emu_quirk(struct snd_usb_substream *subs, 1418 - struct audioformat *fmt) 1417 + const struct audioformat *fmt) 1419 1418 { 1420 1419 unsigned char emu_samplerate_id = 0; 1421 1420 ··· 1477 1476 } 1478 1477 1479 1478 void snd_usb_set_format_quirk(struct snd_usb_substream *subs, 1480 - struct audioformat *fmt) 1479 + const struct audioformat *fmt) 1481 1480 { 1482 1481 switch (subs->stream->chip->usb_id) { 1483 1482 case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */ ··· 1544 1543 } 1545 1544 1546 1545 int snd_usb_select_mode_quirk(struct snd_usb_audio *chip, 1547 - struct audioformat *fmt) 1546 + const struct audioformat *fmt) 1548 1547 { 1549 1548 struct usb_device *dev = chip->dev; 1550 1549 int err;
+3 -3
sound/usb/quirks.h
··· 26 26 unsigned int usb_id); 27 27 28 28 void snd_usb_set_format_quirk(struct snd_usb_substream *subs, 29 - struct audioformat *fmt); 29 + const struct audioformat *fmt); 30 30 31 31 bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip); 32 32 33 33 int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, 34 - struct audioformat *fp); 34 + const struct audioformat *fp); 35 35 36 36 void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep); 37 37 ··· 41 41 __u16 index, void *data, __u16 size); 42 42 43 43 int snd_usb_select_mode_quirk(struct snd_usb_audio *chip, 44 - struct audioformat *fmt); 44 + const struct audioformat *fmt); 45 45 46 46 u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, 47 47 struct audioformat *fp,