Skip to content

Commit

Permalink
ALSA: usb-audio: Constify audioformat pointer references
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Dylan Robinson <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Nov 23, 2020
1 parent c15871e commit cab941b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 38 deletions.
4 changes: 2 additions & 2 deletions sound/usb/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ struct snd_usb_endpoint {
bool need_setup; /* (re-)need for configure? */

/* for hw constraints */
struct audioformat *cur_audiofmt;
const struct audioformat *cur_audiofmt;
unsigned int cur_rate;
snd_pcm_format_t cur_format;
unsigned int cur_channels;
Expand All @@ -142,7 +142,7 @@ struct snd_usb_substream {
int direction; /* playback or capture */
int interface; /* current interface */
int endpoint; /* assigned endpoint */
struct audioformat *cur_audiofmt; /* current audioformat pointer (for hw_params callback) */
const struct audioformat *cur_audiofmt; /* current audioformat pointer (for hw_params callback) */
struct snd_usb_power_domain *str_pd; /* UAC3 Power Domain for streaming path */
snd_pcm_format_t pcm_format; /* current audio format (for hw_params callback) */
unsigned int channels; /* current number of channels (for hw_params callback) */
Expand Down
16 changes: 8 additions & 8 deletions sound/usb/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static int uac_clock_selector_set_val(struct snd_usb_audio *chip, int selector_i
}

static bool uac_clock_source_is_valid_quirk(struct snd_usb_audio *chip,
struct audioformat *fmt,
const struct audioformat *fmt,
int source_id)
{
bool ret = false;
Expand Down Expand Up @@ -215,7 +215,7 @@ static bool uac_clock_source_is_valid_quirk(struct snd_usb_audio *chip,
}

static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
struct audioformat *fmt,
const struct audioformat *fmt,
int source_id)
{
int err;
Expand Down Expand Up @@ -264,7 +264,7 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
}

static int __uac_clock_find_source(struct snd_usb_audio *chip,
struct audioformat *fmt, int entity_id,
const struct audioformat *fmt, int entity_id,
unsigned long *visited, bool validate)
{
struct uac_clock_source_descriptor *source;
Expand Down Expand Up @@ -358,7 +358,7 @@ static int __uac_clock_find_source(struct snd_usb_audio *chip,
}

static int __uac3_clock_find_source(struct snd_usb_audio *chip,
struct audioformat *fmt, int entity_id,
const struct audioformat *fmt, int entity_id,
unsigned long *visited, bool validate)
{
struct uac3_clock_source_descriptor *source;
Expand Down Expand Up @@ -464,7 +464,7 @@ static int __uac3_clock_find_source(struct snd_usb_audio *chip,
* Returns the clock source UnitID (>=0) on success, or an error.
*/
int snd_usb_clock_find_source(struct snd_usb_audio *chip,
struct audioformat *fmt, bool validate)
const struct audioformat *fmt, bool validate)
{
DECLARE_BITMAP(visited, 256);
memset(visited, 0, sizeof(visited));
Expand All @@ -482,7 +482,7 @@ int snd_usb_clock_find_source(struct snd_usb_audio *chip,
}

static int set_sample_rate_v1(struct snd_usb_audio *chip,
struct audioformat *fmt, int rate)
const struct audioformat *fmt, int rate)
{
struct usb_device *dev = chip->dev;
struct usb_host_interface *alts;
Expand Down Expand Up @@ -611,7 +611,7 @@ int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio *chip,
}

static int set_sample_rate_v2v3(struct snd_usb_audio *chip,
struct audioformat *fmt, int rate)
const struct audioformat *fmt, int rate)
{
int cur_rate, prev_rate;
int clock;
Expand Down Expand Up @@ -663,7 +663,7 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip,
}

int snd_usb_init_sample_rate(struct snd_usb_audio *chip,
struct audioformat *fmt, int rate)
const struct audioformat *fmt, int rate)
{
usb_audio_dbg(chip, "%d:%d Set sample rate %d, clock %d\n",
fmt->iface, fmt->altsetting, rate, fmt->clock);
Expand Down
4 changes: 2 additions & 2 deletions sound/usb/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#define __USBAUDIO_CLOCK_H

int snd_usb_init_sample_rate(struct snd_usb_audio *chip,
struct audioformat *fmt, int rate);
const struct audioformat *fmt, int rate);

int snd_usb_clock_find_source(struct snd_usb_audio *chip,
struct audioformat *fmt, bool validate);
const struct audioformat *fmt, bool validate);

int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio *chip,
const struct audioformat *fmt,
Expand Down
2 changes: 1 addition & 1 deletion sound/usb/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ bool snd_usb_endpoint_compatible(struct snd_usb_audio *chip,
*/
struct snd_usb_endpoint *
snd_usb_endpoint_open(struct snd_usb_audio *chip,
struct audioformat *fp,
const struct audioformat *fp,
const struct snd_pcm_hw_params *params,
bool is_sync_ep)
{
Expand Down
2 changes: 1 addition & 1 deletion sound/usb/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int snd_usb_add_endpoint(struct snd_usb_audio *chip, int ep_num, int type);

struct snd_usb_endpoint *
snd_usb_endpoint_open(struct snd_usb_audio *chip,
struct audioformat *fp,
const struct audioformat *fp,
const struct snd_pcm_hw_params *params,
bool is_sync_ep);
void snd_usb_endpoint_close(struct snd_usb_audio *chip,
Expand Down
32 changes: 16 additions & 16 deletions sound/usb/pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream
/*
* find a matching audio format
*/
static struct audioformat *
static const struct audioformat *
find_format(struct list_head *fmt_list_head, snd_pcm_format_t format,
unsigned int rate, unsigned int channels, bool strict_match,
struct snd_usb_substream *subs)
{
struct audioformat *fp;
struct audioformat *found = NULL;
const struct audioformat *fp;
const struct audioformat *found = NULL;
int cur_attr = 0, attr;

list_for_each_entry(fp, fmt_list_head, list) {
Expand Down Expand Up @@ -141,7 +141,7 @@ find_format(struct list_head *fmt_list_head, snd_pcm_format_t format,
return found;
}

static struct audioformat *
static const struct audioformat *
find_substream_format(struct snd_usb_substream *subs,
const struct snd_pcm_hw_params *params)
{
Expand Down Expand Up @@ -182,7 +182,7 @@ static int init_pitch_v2(struct snd_usb_audio *chip, int ep)
* initialize the pitch control and sample rate
*/
int snd_usb_init_pitch(struct snd_usb_audio *chip,
struct audioformat *fmt)
const struct audioformat *fmt)
{
int err;

Expand Down Expand Up @@ -641,14 +641,14 @@ find_matching_substream(struct snd_usb_audio *chip, int stream, int ep_num,
return NULL;
}

static struct audioformat *
static const struct audioformat *
find_implicit_fb_sync_format(struct snd_usb_audio *chip,
const struct audioformat *target,
const struct snd_pcm_hw_params *params,
int stream)
{
struct snd_usb_substream *subs;
struct audioformat *fp, *sync_fmt;
const struct audioformat *fp, *sync_fmt;
int score, high_score;

subs = find_matching_substream(chip, stream, target->sync_ep,
Expand Down Expand Up @@ -726,8 +726,8 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
{
struct snd_usb_substream *subs = substream->runtime->private_data;
struct snd_usb_audio *chip = subs->stream->chip;
struct audioformat *fmt;
struct audioformat *sync_fmt;
const struct audioformat *fmt;
const struct audioformat *sync_fmt;
int ret;

ret = snd_media_start_pipeline(subs);
Expand Down Expand Up @@ -918,7 +918,7 @@ static const struct snd_pcm_hardware snd_usb_hardware =

static int hw_check_valid_format(struct snd_usb_substream *subs,
struct snd_pcm_hw_params *params,
struct audioformat *fp)
const struct audioformat *fp)
{
struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
struct snd_interval *ct = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
Expand Down Expand Up @@ -995,7 +995,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
const struct audioformat *fp;
struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
unsigned int rmin, rmax, r;
int i;
Expand Down Expand Up @@ -1028,7 +1028,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
const struct audioformat *fp;
struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
unsigned int rmin, rmax;

Expand All @@ -1049,7 +1049,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
const struct audioformat *fp;
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
u64 fbits;
u32 oldbits[2];
Expand Down Expand Up @@ -1080,7 +1080,7 @@ static int hw_rule_period_time(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
const struct audioformat *fp;
struct snd_interval *it;
unsigned char min_datainterval;
unsigned int pmin;
Expand Down Expand Up @@ -1109,7 +1109,7 @@ static int apply_hw_constraint_from_sync(struct snd_pcm_runtime *runtime,
{
struct snd_usb_audio *chip = subs->stream->chip;
struct snd_usb_endpoint *ep;
struct audioformat *fp;
const struct audioformat *fp;
int err;

list_for_each_entry(fp, &subs->fmt_list, list) {
Expand Down Expand Up @@ -1170,7 +1170,7 @@ static int apply_hw_constraint_from_sync(struct snd_pcm_runtime *runtime,
static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs)
{
struct snd_usb_audio *chip = subs->stream->chip;
struct audioformat *fp;
const struct audioformat *fp;
unsigned int pt, ptmin;
int param_period_time_if_needed = -1;
int err;
Expand Down
2 changes: 1 addition & 1 deletion sound/usb/pcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int snd_usb_pcm_suspend(struct snd_usb_stream *as);
int snd_usb_pcm_resume(struct snd_usb_stream *as);

int snd_usb_init_pitch(struct snd_usb_audio *chip,
struct audioformat *fmt);
const struct audioformat *fmt);
void snd_usb_preallocate_buffer(struct snd_usb_substream *subs);

int snd_usb_audioformat_set_sync_ep(struct snd_usb_audio *chip,
Expand Down
9 changes: 5 additions & 4 deletions sound/usb/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,8 @@ int snd_usb_apply_boot_quirk_once(struct usb_device *dev,
/*
* check if the device uses big-endian samples
*/
int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
int snd_usb_is_big_endian_format(struct snd_usb_audio *chip,
const struct audioformat *fp)
{
/* it depends on altsetting whether the device is big-endian or not */
switch (chip->usb_id) {
Expand Down Expand Up @@ -1414,7 +1415,7 @@ enum {
};

static void set_format_emu_quirk(struct snd_usb_substream *subs,
struct audioformat *fmt)
const struct audioformat *fmt)
{
unsigned char emu_samplerate_id = 0;

Expand Down Expand Up @@ -1476,7 +1477,7 @@ static int pioneer_djm_set_format_quirk(struct snd_usb_substream *subs)
}

void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
struct audioformat *fmt)
const struct audioformat *fmt)
{
switch (subs->stream->chip->usb_id) {
case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
Expand Down Expand Up @@ -1543,7 +1544,7 @@ static bool is_itf_usb_dsd_dac(unsigned int id)
}

int snd_usb_select_mode_quirk(struct snd_usb_audio *chip,
struct audioformat *fmt)
const struct audioformat *fmt)
{
struct usb_device *dev = chip->dev;
int err;
Expand Down
6 changes: 3 additions & 3 deletions sound/usb/quirks.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ int snd_usb_apply_boot_quirk_once(struct usb_device *dev,
unsigned int usb_id);

void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
struct audioformat *fmt);
const struct audioformat *fmt);

bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip);

int snd_usb_is_big_endian_format(struct snd_usb_audio *chip,
struct audioformat *fp);
const struct audioformat *fp);

void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep);

Expand All @@ -41,7 +41,7 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
__u16 index, void *data, __u16 size);

int snd_usb_select_mode_quirk(struct snd_usb_audio *chip,
struct audioformat *fmt);
const struct audioformat *fmt);

u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
struct audioformat *fp,
Expand Down

0 comments on commit cab941b

Please sign in to comment.