Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50bdb123 authored by Peter Senna Tschudin's avatar Peter Senna Tschudin Committed by Greg Kroah-Hartman
Browse files

usb/host/fotg210: Add function scan_frame_queue()



checkpatch complains about too many leading tabs because the if
statement starts after 6 tabs:

scan_iosoc() -> for() -> while() -> switch() -> if() -> for() -> if()

There is also a goto statement going backwards in case of failure. This
patch creates a new inline function named scan_frame_queue() containing
the last 4 nesting levels, and removes the need of backwards goto,
making the code easier to read. After the patch it becomes:

scan_iosoc() -> for() -> while() -> scan_frame_queue()

Signed-off-by: default avatarPeter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 32fb1939
Loading
Loading
Loading
Loading
+76 −67
Original line number Diff line number Diff line
@@ -4609,35 +4609,14 @@ done:
	return status;
}

/*-------------------------------------------------------------------------*/

static void scan_isoc(struct fotg210_hcd *fotg210)
static inline int scan_frame_queue(struct fotg210_hcd *fotg210, unsigned frame,
		unsigned now_frame, bool live)
{
	unsigned	uf, now_frame, frame;
	unsigned	fmask = fotg210->periodic_size - 1;
	bool		modified, live;

	/*
	 * When running, scan from last scan point up to "now"
	 * else clean up by scanning everything that's left.
	 * Touches as few pages as possible:  cache-friendly.
	 */
	if (fotg210->rh_state >= FOTG210_RH_RUNNING) {
		uf = fotg210_read_frame_index(fotg210);
		now_frame = (uf >> 3) & fmask;
		live = true;
	} else  {
		now_frame = (fotg210->next_frame - 1) & fmask;
		live = false;
	}
	fotg210->now_frame = now_frame;

	frame = fotg210->next_frame;
	for (;;) {
	unsigned uf;
	bool modified;
	union fotg210_shadow q, *q_p;
	__hc32 type, *hw_p;

restart:
	/* scan each element in frame's queue for completions */
	q_p = &fotg210->pshadow[frame];
	hw_p = &fotg210->periodic[frame];
@@ -4645,7 +4624,7 @@ restart:
	type = Q_NEXT_TYPE(fotg210, *hw_p);
	modified = false;

		while (q.ptr != NULL) {
	while (q.ptr) {
		switch (hc32_to_cpu(fotg210, type)) {
		case Q_TYPE_ITD:
			/* If this ITD is still active, leave it for
@@ -4695,8 +4674,38 @@ restart:

		/* assume completion callbacks modify the queue */
		if (unlikely(modified && fotg210->isoc_count > 0))
				goto restart;
			return -EINVAL;
	}
	return 0;
}

static void scan_isoc(struct fotg210_hcd *fotg210)
{
	unsigned uf, now_frame, frame, ret;
	unsigned fmask = fotg210->periodic_size - 1;
	bool live;

	/*
	 * When running, scan from last scan point up to "now"
	 * else clean up by scanning everything that's left.
	 * Touches as few pages as possible:  cache-friendly.
	 */
	if (fotg210->rh_state >= FOTG210_RH_RUNNING) {
		uf = fotg210_read_frame_index(fotg210);
		now_frame = (uf >> 3) & fmask;
		live = true;
	} else  {
		now_frame = (fotg210->next_frame - 1) & fmask;
		live = false;
	}
	fotg210->now_frame = now_frame;

	frame = fotg210->next_frame;
	for (;;) {
		ret = 1;
		while (ret != 0)
			ret = scan_frame_queue(fotg210, frame,
					now_frame, live);

		/* Stop when we have reached the current frame */
		if (frame == now_frame)