Commit a829dd5b authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: usx2y: Coding style fixes

This patch fixes various trivial coding-style issues in usx2y code,
such as:
* the assginments in if condition
* comparison order with constants
* NULL / zero checks
* unsigned -> unsigned int
* addition of braces in control blocks
* debug print with function names
* move local variables in block into function head
* reduction of too nested indentations

No functional changes.

Link: https://lore.kernel.org/r/20210517131545.27252-4-tiwai@suse.de


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 4c0a58ef
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -114,9 +114,9 @@ static vm_fault_t usb_stream_hwdep_vm_fault(struct vm_fault *vmf)
		goto unlock;

	offset = vmf->pgoff << PAGE_SHIFT;
	if (offset < PAGE_ALIGN(s->read_size))
	if (offset < PAGE_ALIGN(s->read_size)) {
		vaddr = (char *)s + offset;
	else {
	} else {
		offset -= PAGE_ALIGN(s->read_size);
		if (offset >= PAGE_ALIGN(s->write_size))
			goto unlock;
@@ -238,7 +238,7 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw,
					  struct file *file, poll_table *wait)
{
	struct us122l	*us122l = hw->private_data;
	unsigned	*polled;
	unsigned int	*polled;
	__poll_t	mask;

	poll_wait(file, &us122l->sk.sleep, wait);
@@ -255,9 +255,10 @@ static __poll_t usb_stream_hwdep_poll(struct snd_hwdep *hw,
			if (*polled != s->periods_done) {
				*polled = s->periods_done;
				mask = EPOLLIN | EPOLLOUT | EPOLLWRNORM;
			} else
			} else {
				mask = 0;
			}
		}
		mutex_unlock(&us122l->mutex);
	}
	return mask;
@@ -294,11 +295,11 @@ static int us122l_set_sample_rate(struct usb_device *dev, int rate)
}

static bool us122l_start(struct us122l *us122l,
			 unsigned rate, unsigned period_frames)
			 unsigned int rate, unsigned int period_frames)
{
	struct list_head *p;
	int err;
	unsigned use_packsize = 0;
	unsigned int use_packsize = 0;
	bool success = false;

	if (us122l->dev->speed == USB_SPEED_HIGH) {
@@ -331,7 +332,7 @@ static bool us122l_start(struct us122l *us122l,
	err = usb_stream_start(&us122l->sk);
	if (err < 0) {
		us122l_stop(us122l);
		snd_printk(KERN_ERR "us122l_start error %i\n", err);
		snd_printk(KERN_ERR "%s error %i\n", __func__, err);
		goto out;
	}
	list_for_each(p, &us122l->midi_list)
@@ -342,12 +343,12 @@ static bool us122l_start(struct us122l *us122l,
}

static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
				  unsigned cmd, unsigned long arg)
				  unsigned int cmd, unsigned long arg)
{
	struct usb_stream_config cfg;
	struct us122l *us122l = hw->private_data;
	struct usb_stream *s;
	unsigned min_period_frames;
	unsigned int min_period_frames;
	int err = 0;
	bool high_speed;

@@ -388,9 +389,9 @@ static int usb_stream_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,

	mutex_lock(&us122l->mutex);
	s = us122l->sk.s;
	if (!us122l->master)
	if (!us122l->master) {
		us122l->master = file;
	else if (us122l->master != file) {
	} else if (us122l->master != file) {
		if (!s || memcmp(&cfg, &s->cfg, sizeof(cfg))) {
			err = -EIO;
			goto unlock;
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ struct us122l {

	struct mutex		mutex;
	struct file		*first;
	unsigned		second_periods_polled;
	unsigned int		second_periods_polled;
	struct file		*master;
	struct file		*slave;
	struct list_head	midi_list;
+20 −18
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ static __poll_t snd_us428ctls_poll(struct snd_hwdep *hw, struct file *file, poll

	poll_wait(file, &us428->us428ctls_wait_queue_head, wait);

	if (shm != NULL && shm->ctl_snapshot_last != shm->ctl_snapshot_red)
	if (shm && shm->ctl_snapshot_last != shm->ctl_snapshot_red)
		mask |= EPOLLIN;

	return mask;
@@ -114,7 +114,7 @@ static int snd_usx2y_hwdep_dsp_status(struct snd_hwdep *hw,
		id = USX2Y_TYPE_428;
		break;
	}
	if (0 > id)
	if (id < 0)
		return -ENODEV;
	strcpy(info->id, type_ids[id]);
	info->num_dsps = 2;		// 0: Prepad Data, 1: FPGA Code
@@ -158,7 +158,7 @@ static int usx2y_create_usbmidi(struct snd_card *card)
		le16_to_cpu(dev->descriptor.idProduct) == USB_ID_US428 ?
		&quirk_2 : &quirk_1;

	snd_printdd("usx2y_create_usbmidi\n");
	snd_printdd("%s\n", __func__);
	return snd_usbmidi_create(card, iface, &usx2y(card)->midi_list, quirk);
}

@@ -166,20 +166,21 @@ static int usx2y_create_alsa_devices(struct snd_card *card)
{
	int err;

	do {
		if ((err = usx2y_create_usbmidi(card)) < 0) {
			snd_printk(KERN_ERR "usx2y_create_alsa_devices: usx2y_create_usbmidi error %i\n", err);
			break;
	err = usx2y_create_usbmidi(card);
	if (err < 0) {
		snd_printk(KERN_ERR "%s: usx2y_create_usbmidi error %i\n", __func__, err);
		return err;
	}
		if ((err = usx2y_audio_create(card)) < 0)
			break;
		if ((err = usx2y_hwdep_pcm_new(card)) < 0)
			break;
		if ((err = snd_card_register(card)) < 0)
			break;
	} while (0);

	err = usx2y_audio_create(card);
	if (err < 0)
		return err;
	err = usx2y_hwdep_pcm_new(card);
	if (err < 0)
		return err;
	err = snd_card_register(card);
	if (err < 0)
		return err;
	return 0;
}

static int snd_usx2y_hwdep_dsp_load(struct snd_hwdep *hw,
@@ -233,7 +234,8 @@ int usx2y_hwdep_new(struct snd_card *card, struct usb_device *device)
	int err;
	struct snd_hwdep *hw;

	if ((err = snd_hwdep_new(card, SND_USX2Y_LOADER_ID, 0, &hw)) < 0)
	err = snd_hwdep_new(card, SND_USX2Y_LOADER_ID, 0, &hw);
	if (err < 0)
		return err;

	hw->iface = SNDRV_HWDEP_IFACE_USX2Y;
+18 −14
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@

/*                             setup                                  */

static unsigned usb_stream_next_packet_size(struct usb_stream_kernel *sk)
static unsigned int usb_stream_next_packet_size(struct usb_stream_kernel *sk)
{
	struct usb_stream *s = sk->s;

@@ -44,7 +44,8 @@ static void playback_prep_freqn(struct usb_stream_kernel *sk, struct urb *urb)
		    lb, s->period_size);
}

static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
static int init_pipe_urbs(struct usb_stream_kernel *sk,
			  unsigned int use_packsize,
			  struct urb **urbs, char *transfer,
			  struct usb_device *dev, int pipe)
{
@@ -82,7 +83,7 @@ static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
	return 0;
}

static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
static int init_urbs(struct usb_stream_kernel *sk, unsigned int use_packsize,
		     struct usb_device *dev, int in_pipe, int out_pipe)
{
	struct usb_stream	*s = sk->s;
@@ -112,7 +113,7 @@ static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
 * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
 * this will overflow at approx 524 kHz
 */
static inline unsigned get_usb_full_speed_rate(unsigned rate)
static inline unsigned int get_usb_full_speed_rate(unsigned int rate)
{
	return ((rate << 13) + 62) / 125;
}
@@ -121,7 +122,7 @@ static inline unsigned get_usb_full_speed_rate(unsigned rate)
 * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
 * this will overflow at approx 4 MHz
 */
static inline unsigned get_usb_high_speed_rate(unsigned rate)
static inline unsigned int get_usb_high_speed_rate(unsigned int rate)
{
	return ((rate << 10) + 62) / 125;
}
@@ -129,7 +130,7 @@ static inline unsigned get_usb_high_speed_rate(unsigned rate)
void usb_stream_free(struct usb_stream_kernel *sk)
{
	struct usb_stream *s;
	unsigned u;
	unsigned int u;

	for (u = 0; u < USB_STREAM_NURBS; ++u) {
		usb_free_urb(sk->inurb[u]);
@@ -150,9 +151,12 @@ void usb_stream_free(struct usb_stream_kernel *sk)

struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
				  struct usb_device *dev,
				  unsigned in_endpoint, unsigned out_endpoint,
				  unsigned sample_rate, unsigned use_packsize,
				  unsigned period_frames, unsigned frame_size)
				  unsigned int in_endpoint,
				  unsigned int out_endpoint,
				  unsigned int sample_rate,
				  unsigned int use_packsize,
				  unsigned int period_frames,
				  unsigned int frame_size)
{
	int packets, max_packsize;
	int in_pipe, out_pipe;
@@ -528,7 +532,7 @@ static void stream_start(struct usb_stream_kernel *sk,
	if (s->state >= usb_stream_sync1) {
		int l, p, max_diff, max_diff_0;
		int urb_size = 0;
		unsigned frames_per_packet, min_frames = 0;
		unsigned int frames_per_packet, min_frames = 0;

		frames_per_packet = (s->period_size - s->idle_insize);
		frames_per_packet <<= 8;
@@ -570,7 +574,7 @@ static void stream_start(struct usb_stream_kernel *sk,
				(s->inpacket_head + 1) % s->inpackets;
			s->next_inpacket_split_at = 0;
		} else {
			unsigned split = s->inpacket_head;
			unsigned int split = s->inpacket_head;

			l = s->idle_insize;
			while (l > s->inpacket[split].length) {
+13 −10
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ struct usb_stream_kernel {

	void *write_page;

	unsigned n_o_ps;
	unsigned int n_o_ps;

	struct urb *inurb[USB_STREAM_NURBS];
	struct urb *idle_inurb;
@@ -26,18 +26,21 @@ struct usb_stream_kernel {

	wait_queue_head_t sleep;

	unsigned out_phase;
	unsigned out_phase_peeked;
	unsigned freqn;
	unsigned int out_phase;
	unsigned int out_phase_peeked;
	unsigned int freqn;
};

struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
				  struct usb_device *dev,
				  unsigned in_endpoint, unsigned out_endpoint,
				  unsigned sample_rate, unsigned use_packsize,
				  unsigned period_frames, unsigned frame_size);
void usb_stream_free(struct usb_stream_kernel *);
int usb_stream_start(struct usb_stream_kernel *);
void usb_stream_stop(struct usb_stream_kernel *);
				  unsigned int in_endpoint,
				  unsigned int out_endpoint,
				  unsigned int sample_rate,
				  unsigned int use_packsize,
				  unsigned int period_frames,
				  unsigned int frame_size);
void usb_stream_free(struct usb_stream_kernel *sk);
int usb_stream_start(struct usb_stream_kernel *sk);
void usb_stream_stop(struct usb_stream_kernel *sk);

#endif /* __USB_STREAM_H */
Loading