2015-12-12 01:19:53

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 00/10] usb: host: ehci-sched: cleanup

Cleanup done with the help of coccinelle, checkpatch and cppcheck tools.

Geyslan G. Bem (10):
usb: host: ehci-sched: refactor scan_isoc function
usb: host: ehci-sched: move constants to right
usb: host: ehci-sched: remove useless assignments
usb: host: ehci-sched: add spaces around operators
usb: host: ehci-sched: remove prohibited spaces
usb: host: ehci-sched: remove useless else branch
usb: host: ehci-sched: use C89-style comments
usb: host: ehci-sched: add line after declarations
usb: host: ehci-sched: use sizeof operator with parens
usb: host: ehci-sched: remove unnecessary braces

drivers/usb/host/ehci-sched.c | 523 +++++++++++++++++++++---------------------
1 file changed, 264 insertions(+), 259 deletions(-)

--
2.6.3


2015-12-12 01:20:07

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 01/10] usb: host: ehci-sched: refactor scan_isoc function

This patch removes an infinite 'for' loop and makes use of the already
existing 'restart' tag instead, reducing one leading tab.

The comments and code were corrected conforming coding style.

Tested by compilation only.
Caught by checkpatch:
WARNING: Too many leading tabs - consider code refactoring

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 203 ++++++++++++++++++++++--------------------
1 file changed, 104 insertions(+), 99 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index f9a3327..86b2484 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -2383,6 +2383,9 @@ static void scan_isoc(struct ehci_hcd *ehci)
unsigned fmask = ehci->periodic_size - 1;
bool modified, live;

+ union ehci_shadow q, *q_p;
+ __hc32 type, *hw_p;
+
/*
* When running, scan from last scan point up to "now"
* else clean up by scanning everything that's left.
@@ -2399,119 +2402,121 @@ static void scan_isoc(struct ehci_hcd *ehci)
ehci->now_frame = now_frame;

frame = ehci->last_iso_frame;
- for (;;) {
- union ehci_shadow q, *q_p;
- __hc32 type, *hw_p;

restart:
- /* scan each element in frame's queue for completions */
- q_p = &ehci->pshadow [frame];
- hw_p = &ehci->periodic [frame];
- q.ptr = q_p->ptr;
- type = Q_NEXT_TYPE(ehci, *hw_p);
- modified = false;
-
- while (q.ptr != NULL) {
- switch (hc32_to_cpu(ehci, type)) {
- case Q_TYPE_ITD:
- /* If this ITD is still active, leave it for
- * later processing ... check the next entry.
- * No need to check for activity unless the
- * frame is current.
- */
- if (frame == now_frame && live) {
- rmb();
- for (uf = 0; uf < 8; uf++) {
- if (q.itd->hw_transaction[uf] &
- ITD_ACTIVE(ehci))
- break;
- }
- if (uf < 8) {
- q_p = &q.itd->itd_next;
- hw_p = &q.itd->hw_next;
- type = Q_NEXT_TYPE(ehci,
- q.itd->hw_next);
- q = *q_p;
+ /* Scan each element in frame's queue for completions */
+ q_p = &ehci->pshadow[frame];
+ hw_p = &ehci->periodic[frame];
+ q.ptr = q_p->ptr;
+ type = Q_NEXT_TYPE(ehci, *hw_p);
+ modified = false;
+
+ while (q.ptr != NULL) {
+ switch (hc32_to_cpu(ehci, type)) {
+ case Q_TYPE_ITD:
+ /*
+ * If this ITD is still active, leave it for
+ * later processing ... check the next entry.
+ * No need to check for activity unless the
+ * frame is current.
+ */
+ if (frame == now_frame && live) {
+ rmb();
+ for (uf = 0; uf < 8; uf++) {
+ if (q.itd->hw_transaction[uf] &
+ ITD_ACTIVE(ehci))
break;
- }
}
-
- /* Take finished ITDs out of the schedule
- * and process them: recycle, maybe report
- * URB completion. HC won't cache the
- * pointer for much longer, if at all.
- */
- *q_p = q.itd->itd_next;
- if (!ehci->use_dummy_qh ||
- q.itd->hw_next != EHCI_LIST_END(ehci))
- *hw_p = q.itd->hw_next;
- else
- *hw_p = cpu_to_hc32(ehci,
- ehci->dummy->qh_dma);
- type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
- wmb();
- modified = itd_complete (ehci, q.itd);
- q = *q_p;
- break;
- case Q_TYPE_SITD:
- /* If this SITD is still active, leave it for
- * later processing ... check the next entry.
- * No need to check for activity unless the
- * frame is current.
- */
- if (((frame == now_frame) ||
- (((frame + 1) & fmask) == now_frame))
- && live
- && (q.sitd->hw_results &
- SITD_ACTIVE(ehci))) {
-
- q_p = &q.sitd->sitd_next;
- hw_p = &q.sitd->hw_next;
+ if (uf < 8) {
+ q_p = &q.itd->itd_next;
+ hw_p = &q.itd->hw_next;
type = Q_NEXT_TYPE(ehci,
- q.sitd->hw_next);
+ q.itd->hw_next);
q = *q_p;
break;
}
+ }

- /* Take finished SITDs out of the schedule
- * and process them: recycle, maybe report
- * URB completion.
- */
- *q_p = q.sitd->sitd_next;
- if (!ehci->use_dummy_qh ||
- q.sitd->hw_next != EHCI_LIST_END(ehci))
- *hw_p = q.sitd->hw_next;
- else
- *hw_p = cpu_to_hc32(ehci,
- ehci->dummy->qh_dma);
- type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
- wmb();
- modified = sitd_complete (ehci, q.sitd);
+ /*
+ * Take finished ITDs out of the schedule
+ * and process them: recycle, maybe report
+ * URB completion. HC won't cache the
+ * pointer for much longer, if at all.
+ */
+ *q_p = q.itd->itd_next;
+ if (!ehci->use_dummy_qh ||
+ q.itd->hw_next != EHCI_LIST_END(ehci))
+ *hw_p = q.itd->hw_next;
+ else
+ *hw_p = cpu_to_hc32(ehci,
+ ehci->dummy->qh_dma);
+ type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
+ wmb();
+ modified = itd_complete(ehci, q.itd);
+ q = *q_p;
+ break;
+ case Q_TYPE_SITD:
+ /*
+ * If this SITD is still active, leave it for
+ * later processing ... check the next entry.
+ * No need to check for activity unless the
+ * frame is current.
+ */
+ if (((frame == now_frame) ||
+ (((frame + 1) & fmask) == now_frame))
+ && live
+ && (q.sitd->hw_results &
+ SITD_ACTIVE(ehci))) {
+
+ q_p = &q.sitd->sitd_next;
+ hw_p = &q.sitd->hw_next;
+ type = Q_NEXT_TYPE(ehci,
+ q.sitd->hw_next);
q = *q_p;
break;
- default:
- ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
- type, frame, q.ptr);
- // BUG ();
- /* FALL THROUGH */
- case Q_TYPE_QH:
- case Q_TYPE_FSTN:
- /* End of the iTDs and siTDs */
- q.ptr = NULL;
- break;
}

- /* assume completion callbacks modify the queue */
- if (unlikely(modified && ehci->isoc_count > 0))
- goto restart;
- }
-
- /* Stop when we have reached the current frame */
- if (frame == now_frame)
+ /*
+ * Take finished SITDs out of the schedule
+ * and process them: recycle, maybe report
+ * URB completion.
+ */
+ *q_p = q.sitd->sitd_next;
+ if (!ehci->use_dummy_qh ||
+ q.sitd->hw_next != EHCI_LIST_END(ehci))
+ *hw_p = q.sitd->hw_next;
+ else
+ *hw_p = cpu_to_hc32(ehci,
+ ehci->dummy->qh_dma);
+ type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
+ wmb();
+ modified = sitd_complete(ehci, q.sitd);
+ q = *q_p;
break;
+ default:
+ ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
+ type, frame, q.ptr);
+ /* BUG(); */
+ /* FALL THROUGH */
+ case Q_TYPE_QH:
+ case Q_TYPE_FSTN:
+ /* End of the iTDs and siTDs */
+ q.ptr = NULL;
+ break;
+ }

- /* The last frame may still have active siTDs */
- ehci->last_iso_frame = frame;
- frame = (frame + 1) & fmask;
+ /* Assume completion callbacks modify the queue */
+ if (unlikely(modified && ehci->isoc_count > 0))
+ goto restart;
}
+
+ /* Stop when we have reached the current frame */
+ if (frame == now_frame)
+ return;
+
+ /* The last frame may still have active siTDs */
+ ehci->last_iso_frame = frame;
+ frame = (frame + 1) & fmask;
+
+ goto restart;
}
--
2.6.3

2015-12-12 01:23:32

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 02/10] usb: host: ehci-sched: move constants to right

This patch moves the constants to right.

Tested by compilation only.
Caught by coccinelle:
scripts/coccinelle/misc/compare_const_fl.cocci

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 86b2484..89bc9e4 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -330,7 +330,7 @@ static int __maybe_unused same_tt(struct usb_device *dev1,
*/
static inline unsigned char tt_start_uframe(struct ehci_hcd *ehci, __hc32 mask)
{
- unsigned char smask = QH_SMASK & hc32_to_cpu(ehci, mask);
+ unsigned char smask = hc32_to_cpu(ehci, mask) & QH_SMASK;
if (!smask) {
ehci_err(ehci, "invalid empty smask!\n");
/* uframe 7 can't have bw so this will indicate failure */
@@ -409,11 +409,11 @@ static int tt_available (
* must be empty, so as to not illegally delay
* already scheduled transactions
*/
- if (125 < usecs) {
+ if (usecs > 125) {
int ufs = (usecs / 125);

for (i = uframe; i < (uframe + ufs) && i < 8; i++)
- if (0 < tt_usecs[i])
+ if (tt_usecs[i] > 0)
return 0;
}

--
2.6.3

2015-12-12 01:20:14

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 03/10] usb: host: ehci-sched: remove useless assignments

This patch removes useless assignments.

Tested by compilation only.
Caught by cppcheck.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 89bc9e4..4bb61d5 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -2132,7 +2132,7 @@ sitd_patch(
)
{
struct ehci_iso_packet *uf = &iso_sched->packet [index];
- u64 bufp = uf->bufp;
+ u64 bufp;

sitd->hw_next = EHCI_LIST_END(ehci);
sitd->hw_fullspeed_ep = stream->address;
@@ -2242,7 +2242,7 @@ static bool sitd_complete(struct ehci_hcd *ehci, struct ehci_sitd *sitd)
struct urb *urb = sitd->urb;
struct usb_iso_packet_descriptor *desc;
u32 t;
- int urb_index = -1;
+ int urb_index;
struct ehci_iso_stream *stream = sitd->stream;
struct usb_device *dev;
bool retval = false;
--
2.6.3

2015-12-12 01:20:19

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 04/10] usb: host: ehci-sched: add spaces around operators

This patch adds spaces around operators.

Tested by compilation only.
Caught by checkpatch.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 4bb61d5..f8e8e3f 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -346,7 +346,7 @@ max_tt_usecs[] = { 125, 125, 125, 125, 125, 125, 30, 0 };
static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
{
int i;
- for (i=0; i<7; i++) {
+ for (i = 0; i < 7; i++) {
if (max_tt_usecs[i] < tt_usecs[i]) {
tt_usecs[i+1] += tt_usecs[i] - max_tt_usecs[i];
tt_usecs[i] = max_tt_usecs[i];
--
2.6.3

2015-12-12 01:20:35

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 05/10] usb: host: ehci-sched: remove prohibited spaces

This patch removes prohibited spaces before open parenthesis and open
brackets.

It also removes an assignment inside condition and unnecessary braces in
single statement block.

Tested by compilation only.
Caught by checkpatch.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 265 +++++++++++++++++++++---------------------
1 file changed, 133 insertions(+), 132 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index f8e8e3f..a42ea4d 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -34,7 +34,7 @@
* pre-calculated schedule data to make appending to the queue be quick.
*/

-static int ehci_get_frame (struct usb_hcd *hcd);
+static int ehci_get_frame(struct usb_hcd *hcd);

/*
* periodic_next_shadow - return "next" pointer on shadow list
@@ -73,7 +73,7 @@ shadow_next_periodic(struct ehci_hcd *ehci, union ehci_shadow *periodic,
}

/* caller must hold ehci->lock */
-static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
+static void periodic_unlink(struct ehci_hcd *ehci, unsigned frame, void *ptr)
{
union ehci_shadow *prev_p = &ehci->pshadow[frame];
__hc32 *hw_p = &ehci->periodic[frame];
@@ -375,7 +375,7 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
* limit of 16, specified in USB 2.0 spec section 11.18.4 requirement #4,
* since proper scheduling limits ssplits to less than 16 per uframe.
*/
-static int tt_available (
+static int tt_available(
struct ehci_hcd *ehci,
struct ehci_per_sched *ps,
struct ehci_tt *tt,
@@ -435,7 +435,7 @@ static int tt_available (
* for a periodic transfer starting at the specified frame, using
* all the uframes in the mask.
*/
-static int tt_no_collision (
+static int tt_no_collision(
struct ehci_hcd *ehci,
unsigned period,
struct usb_device *dev,
@@ -455,8 +455,8 @@ static int tt_no_collision (
__hc32 type;
struct ehci_qh_hw *hw;

- here = ehci->pshadow [frame];
- type = Q_NEXT_TYPE(ehci, ehci->periodic [frame]);
+ here = ehci->pshadow[frame];
+ type = Q_NEXT_TYPE(ehci, ehci->periodic[frame]);
while (here.ptr) {
switch (hc32_to_cpu(ehci, type)) {
case Q_TYPE_ITD:
@@ -479,7 +479,7 @@ static int tt_no_collision (
here = here.qh->qh_next;
continue;
case Q_TYPE_SITD:
- if (same_tt (dev, here.sitd->urb->dev)) {
+ if (same_tt(dev, here.sitd->urb->dev)) {
u16 mask;

mask = hc32_to_cpu(ehci, here.sitd
@@ -494,7 +494,7 @@ static int tt_no_collision (
continue;
// case Q_TYPE_FSTN:
default:
- ehci_dbg (ehci,
+ ehci_dbg(ehci,
"periodic frame %d bogus type %d\n",
frame, type);
}
@@ -588,9 +588,9 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
qh->qh_next = here;
if (here.qh)
qh->hw->hw_next = *hw_p;
- wmb ();
+ wmb();
prev->qh = qh;
- *hw_p = QH_NEXT (ehci, qh->qh_dma);
+ *hw_p = QH_NEXT(ehci, qh->qh_dma);
}
}
qh->qh_state = QH_STATE_LINKED;
@@ -633,7 +633,7 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
period = qh->ps.period ? : 1;

for (i = qh->ps.phase; i < ehci->periodic_size; i += period)
- periodic_unlink (ehci, i, qh);
+ periodic_unlink(ehci, i, qh);

/* update per-qh bandwidth for debugfs */
ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->ps.bw_period
@@ -679,7 +679,7 @@ static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
/* if the qh is waiting for unlink, cancel it now */
cancel_unlink_wait_intr(ehci, qh);

- qh_unlink_periodic (ehci, qh);
+ qh_unlink_periodic(ehci, qh);

/* Make sure the unlinks are visible before starting the timer */
wmb();
@@ -763,7 +763,7 @@ static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)

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

-static int check_period (
+static int check_period(
struct ehci_hcd *ehci,
unsigned frame,
unsigned uframe,
@@ -789,7 +789,7 @@ static int check_period (
return 1;
}

-static int check_intr_schedule (
+static int check_intr_schedule(
struct ehci_hcd *ehci,
unsigned frame,
unsigned uframe,
@@ -925,7 +925,7 @@ done:
return status;
}

-static int intr_submit (
+static int intr_submit(
struct ehci_hcd *ehci,
struct urb *urb,
struct list_head *qtd_list,
@@ -940,7 +940,7 @@ static int intr_submit (
/* get endpoint and transfer/schedule data */
epnum = urb->ep->desc.bEndpointAddress;

- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);

if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
status = -ESHUTDOWN;
@@ -951,20 +951,21 @@ static int intr_submit (
goto done_not_linked;

/* get qh and force any scheduling errors */
- INIT_LIST_HEAD (&empty);
+ INIT_LIST_HEAD(&empty);
qh = qh_append_tds(ehci, urb, &empty, epnum, &urb->ep->hcpriv);
if (qh == NULL) {
status = -ENOMEM;
goto done;
}
if (qh->qh_state == QH_STATE_IDLE) {
- if ((status = qh_schedule (ehci, qh)) != 0)
+ status = qh_schedule(ehci, qh);
+ if (status)
goto done;
}

/* then queue the urb's tds to the qh */
qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
- BUG_ON (qh == NULL);
+ BUG_ON(qh == NULL);

/* stuff into the periodic schedule */
if (qh->qh_state == QH_STATE_IDLE) {
@@ -982,9 +983,9 @@ done:
if (unlikely(status))
usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
done_not_linked:
- spin_unlock_irqrestore (&ehci->lock, flags);
+ spin_unlock_irqrestore(&ehci->lock, flags);
if (status)
- qtd_list_free (ehci, urb, qtd_list);
+ qtd_list_free(ehci, urb, qtd_list);

return status;
}
@@ -1022,12 +1023,12 @@ static void scan_intr(struct ehci_hcd *ehci)
/* ehci_iso_stream ops work with both ITD and SITD */

static struct ehci_iso_stream *
-iso_stream_alloc (gfp_t mem_flags)
+iso_stream_alloc(gfp_t mem_flags)
{
struct ehci_iso_stream *stream;

stream = kzalloc(sizeof *stream, mem_flags);
- if (likely (stream != NULL)) {
+ if (likely(stream != NULL)) {
INIT_LIST_HEAD(&stream->td_list);
INIT_LIST_HEAD(&stream->free_list);
stream->next_uframe = NO_FRAME;
@@ -1037,13 +1038,13 @@ iso_stream_alloc (gfp_t mem_flags)
}

static void
-iso_stream_init (
+iso_stream_init(
struct ehci_hcd *ehci,
struct ehci_iso_stream *stream,
struct urb *urb
)
{
- static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f };
+ static const u8 smask_out[] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f };

struct usb_device *dev = urb->dev;
u32 buf1;
@@ -1111,7 +1112,7 @@ iso_stream_init (
think_time = dev->tt ? dev->tt->think_time : 0;
stream->ps.tt_usecs = NS_TO_US(think_time + usb_calc_bus_time(
dev->speed, is_input, 1, maxp));
- hs_transfers = max (1u, (maxp + 187) / 188);
+ hs_transfers = max(1u, (maxp + 187) / 188);
if (is_input) {
u32 tmp;

@@ -1151,7 +1152,7 @@ iso_stream_init (
}

static struct ehci_iso_stream *
-iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
+iso_stream_find(struct ehci_hcd *ehci, struct urb *urb)
{
unsigned epnum;
struct ehci_iso_stream *stream;
@@ -1164,25 +1165,25 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
else
ep = urb->dev->ep_out[epnum];

- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);
stream = ep->hcpriv;

- if (unlikely (stream == NULL)) {
+ if (unlikely(stream == NULL)) {
stream = iso_stream_alloc(GFP_ATOMIC);
- if (likely (stream != NULL)) {
+ if (likely(stream != NULL)) {
ep->hcpriv = stream;
iso_stream_init(ehci, stream, urb);
}

/* if dev->ep [epnum] is a QH, hw is set */
- } else if (unlikely (stream->hw != NULL)) {
- ehci_dbg (ehci, "dev %s ep%d%s, not iso??\n",
+ } else if (unlikely(stream->hw != NULL)) {
+ ehci_dbg(ehci, "dev %s ep%d%s, not iso??\n",
urb->dev->devpath, epnum,
usb_pipein(urb->pipe) ? "in" : "out");
stream = NULL;
}

- spin_unlock_irqrestore (&ehci->lock, flags);
+ spin_unlock_irqrestore(&ehci->lock, flags);
return stream;
}

@@ -1191,16 +1192,16 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
/* ehci_iso_sched ops can be ITD-only or SITD-only */

static struct ehci_iso_sched *
-iso_sched_alloc (unsigned packets, gfp_t mem_flags)
+iso_sched_alloc(unsigned packets, gfp_t mem_flags)
{
struct ehci_iso_sched *iso_sched;
int size = sizeof *iso_sched;

- size += packets * sizeof (struct ehci_iso_packet);
+ size += packets * sizeof(struct ehci_iso_packet);
iso_sched = kzalloc(size, mem_flags);
- if (likely (iso_sched != NULL)) {
- INIT_LIST_HEAD (&iso_sched->td_list);
- }
+ if (likely(iso_sched != NULL))
+ INIT_LIST_HEAD(&iso_sched->td_list);
+
return iso_sched;
}

@@ -1222,17 +1223,17 @@ itd_sched_init(
* when we fit new itds into the schedule.
*/
for (i = 0; i < urb->number_of_packets; i++) {
- struct ehci_iso_packet *uframe = &iso_sched->packet [i];
+ struct ehci_iso_packet *uframe = &iso_sched->packet[i];
unsigned length;
dma_addr_t buf;
u32 trans;

- length = urb->iso_frame_desc [i].length;
- buf = dma + urb->iso_frame_desc [i].offset;
+ length = urb->iso_frame_desc[i].length;
+ buf = dma + urb->iso_frame_desc[i].offset;

trans = EHCI_ISOC_ACTIVE;
trans |= buf & 0x0fff;
- if (unlikely (((i + 1) == urb->number_of_packets))
+ if (unlikely(((i + 1) == urb->number_of_packets))
&& !(urb->transfer_flags & URB_NO_INTERRUPT))
trans |= EHCI_ITD_IOC;
trans |= length << 16;
@@ -1241,13 +1242,13 @@ itd_sched_init(
/* might need to cross a buffer page within a uframe */
uframe->bufp = (buf & ~(u64)0x0fff);
buf += length;
- if (unlikely ((uframe->bufp != (buf & ~(u64)0x0fff))))
+ if (unlikely((uframe->bufp != (buf & ~(u64)0x0fff))))
uframe->cross = 1;
}
}

static void
-iso_sched_free (
+iso_sched_free(
struct ehci_iso_stream *stream,
struct ehci_iso_sched *iso_sched
)
@@ -1255,12 +1256,12 @@ iso_sched_free (
if (!iso_sched)
return;
// caller must hold ehci->lock!
- list_splice (&iso_sched->td_list, &stream->free_list);
- kfree (iso_sched);
+ list_splice(&iso_sched->td_list, &stream->free_list);
+ kfree(iso_sched);
}

static int
-itd_urb_transaction (
+itd_urb_transaction(
struct ehci_iso_stream *stream,
struct ehci_hcd *ehci,
struct urb *urb,
@@ -1274,8 +1275,8 @@ itd_urb_transaction (
struct ehci_iso_sched *sched;
unsigned long flags;

- sched = iso_sched_alloc (urb->number_of_packets, mem_flags);
- if (unlikely (sched == NULL))
+ sched = iso_sched_alloc(urb->number_of_packets, mem_flags);
+ if (unlikely(sched == NULL))
return -ENOMEM;

itd_sched_init(ehci, sched, stream, urb);
@@ -1286,7 +1287,7 @@ itd_urb_transaction (
num_itds = urb->number_of_packets;

/* allocate/init ITDs */
- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);
for (i = 0; i < num_itds; i++) {

/*
@@ -1298,14 +1299,14 @@ itd_urb_transaction (
struct ehci_itd, itd_list);
if (itd->frame == ehci->now_frame)
goto alloc_itd;
- list_del (&itd->itd_list);
+ list_del(&itd->itd_list);
itd_dma = itd->itd_dma;
} else {
alloc_itd:
- spin_unlock_irqrestore (&ehci->lock, flags);
- itd = dma_pool_alloc (ehci->itd_pool, mem_flags,
+ spin_unlock_irqrestore(&ehci->lock, flags);
+ itd = dma_pool_alloc(ehci->itd_pool, mem_flags,
&itd_dma);
- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);
if (!itd) {
iso_sched_free(stream, sched);
spin_unlock_irqrestore(&ehci->lock, flags);
@@ -1313,12 +1314,12 @@ itd_urb_transaction (
}
}

- memset (itd, 0, sizeof *itd);
+ memset(itd, 0, sizeof *itd);
itd->itd_dma = itd_dma;
itd->frame = NO_FRAME;
- list_add (&itd->itd_list, &sched->td_list);
+ list_add(&itd->itd_list, &sched->td_list);
}
- spin_unlock_irqrestore (&ehci->lock, flags);
+ spin_unlock_irqrestore(&ehci->lock, flags);

/* temporarily store schedule info in hcpriv */
urb->hcpriv = sched;
@@ -1385,7 +1386,7 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
}

static inline int
-itd_slot_ok (
+itd_slot_ok(
struct ehci_hcd *ehci,
struct ehci_iso_stream *stream,
unsigned uframe
@@ -1405,7 +1406,7 @@ itd_slot_ok (
}

static inline int
-sitd_slot_ok (
+sitd_slot_ok(
struct ehci_hcd *ehci,
struct ehci_iso_stream *stream,
unsigned uframe,
@@ -1492,7 +1493,7 @@ sitd_slot_ok (
*/

static int
-iso_stream_schedule (
+iso_stream_schedule(
struct ehci_hcd *ehci,
struct urb *urb,
struct ehci_iso_stream *stream
@@ -1693,9 +1694,9 @@ itd_init(struct ehci_hcd *ehci, struct ehci_iso_stream *stream,

/* it's been recently zeroed */
itd->hw_next = EHCI_LIST_END(ehci);
- itd->hw_bufp [0] = stream->buf0;
- itd->hw_bufp [1] = stream->buf1;
- itd->hw_bufp [2] = stream->buf2;
+ itd->hw_bufp[0] = stream->buf0;
+ itd->hw_bufp[1] = stream->buf1;
+ itd->hw_bufp[2] = stream->buf2;

for (i = 0; i < 8; i++)
itd->index[i] = -1;
@@ -1712,13 +1713,13 @@ itd_patch(
u16 uframe
)
{
- struct ehci_iso_packet *uf = &iso_sched->packet [index];
+ struct ehci_iso_packet *uf = &iso_sched->packet[index];
unsigned pg = itd->pg;

// BUG_ON (pg == 6 && uf->cross);

uframe &= 0x07;
- itd->index [uframe] = index;
+ itd->index[uframe] = index;

itd->hw_transaction[uframe] = uf->transaction;
itd->hw_transaction[uframe] |= cpu_to_hc32(ehci, pg << 12);
@@ -1726,7 +1727,7 @@ itd_patch(
itd->hw_bufp_hi[pg] |= cpu_to_hc32(ehci, (u32)(uf->bufp >> 32));

/* iso_frame_desc[].offset must be strictly increasing */
- if (unlikely (uf->cross)) {
+ if (unlikely(uf->cross)) {
u64 bufp = uf->bufp + 4096;

itd->pg = ++pg;
@@ -1736,7 +1737,7 @@ itd_patch(
}

static inline void
-itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
+itd_link(struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
{
union ehci_shadow *prev = &ehci->pshadow[frame];
__hc32 *hw_p = &ehci->periodic[frame];
@@ -1757,7 +1758,7 @@ itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
itd->hw_next = *hw_p;
prev->itd = itd;
itd->frame = frame;
- wmb ();
+ wmb();
*hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD);
}

@@ -1776,7 +1777,7 @@ static void itd_link_urb(

next_uframe = stream->next_uframe & (mod - 1);

- if (unlikely (list_empty(&stream->td_list)))
+ if (unlikely(list_empty(&stream->td_list)))
ehci_to_hcd(ehci)->self.bandwidth_allocated
+= stream->bandwidth;

@@ -1796,12 +1797,12 @@ static void itd_link_urb(

/* ASSERT: no itds for this endpoint in this uframe */

- itd = list_entry (iso_sched->td_list.next,
+ itd = list_entry(iso_sched->td_list.next,
struct ehci_itd, itd_list);
- list_move_tail (&itd->itd_list, &stream->td_list);
+ list_move_tail(&itd->itd_list, &stream->td_list);
itd->stream = stream;
itd->urb = urb;
- itd_init (ehci, stream, itd);
+ itd_init(ehci, stream, itd);
}

uframe = next_uframe & 0x07;
@@ -1823,7 +1824,7 @@ static void itd_link_urb(
stream->next_uframe = next_uframe;

/* don't need that schedule data any more */
- iso_sched_free (stream, iso_sched);
+ iso_sched_free(stream, iso_sched);
urb->hcpriv = stream;

++ehci->isoc_count;
@@ -1855,19 +1856,19 @@ static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)

/* for each uframe with a packet */
for (uframe = 0; uframe < 8; uframe++) {
- if (likely (itd->index[uframe] == -1))
+ if (likely(itd->index[uframe] == -1))
continue;
urb_index = itd->index[uframe];
- desc = &urb->iso_frame_desc [urb_index];
+ desc = &urb->iso_frame_desc[urb_index];

- t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]);
- itd->hw_transaction [uframe] = 0;
+ t = hc32_to_cpup(ehci, &itd->hw_transaction[uframe]);
+ itd->hw_transaction[uframe] = 0;

/* report transfer status */
- if (unlikely (t & ISO_ERRS)) {
+ if (unlikely(t & ISO_ERRS)) {
urb->error_count++;
if (t & EHCI_ISOC_BUF_ERR)
- desc->status = usb_pipein (urb->pipe)
+ desc->status = usb_pipein(urb->pipe)
? -ENOSR /* hc couldn't read */
: -ECOMM; /* hc couldn't write */
else if (t & EHCI_ISOC_BABBLE)
@@ -1880,7 +1881,7 @@ static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)
desc->actual_length = EHCI_ITD_LENGTH(t);
urb->actual_length += desc->actual_length;
}
- } else if (likely ((t & EHCI_ISOC_ACTIVE) == 0)) {
+ } else if (likely((t & EHCI_ISOC_ACTIVE) == 0)) {
desc->status = 0;
desc->actual_length = EHCI_ITD_LENGTH(t);
urb->actual_length += desc->actual_length;
@@ -1891,7 +1892,7 @@ static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)
}

/* handle completion now? */
- if (likely ((urb_index + 1) != urb->number_of_packets))
+ if (likely((urb_index + 1) != urb->number_of_packets))
goto done;

/* ASSERT: it's really the last itd for this urb
@@ -1936,7 +1937,7 @@ done:

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

-static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
+static int itd_submit(struct ehci_hcd *ehci, struct urb *urb,
gfp_t mem_flags)
{
int status = -EINVAL;
@@ -1944,37 +1945,37 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
struct ehci_iso_stream *stream;

/* Get iso_stream head */
- stream = iso_stream_find (ehci, urb);
- if (unlikely (stream == NULL)) {
- ehci_dbg (ehci, "can't get iso stream\n");
+ stream = iso_stream_find(ehci, urb);
+ if (unlikely(stream == NULL)) {
+ ehci_dbg(ehci, "can't get iso stream\n");
return -ENOMEM;
}
if (unlikely(urb->interval != stream->uperiod)) {
- ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
+ ehci_dbg(ehci, "can't change iso interval %d --> %d\n",
stream->uperiod, urb->interval);
goto done;
}

#ifdef EHCI_URB_TRACE
- ehci_dbg (ehci,
+ ehci_dbg(ehci,
"%s %s urb %p ep%d%s len %d, %d pkts %d uframes [%p]\n",
__func__, urb->dev->devpath, urb,
- usb_pipeendpoint (urb->pipe),
- usb_pipein (urb->pipe) ? "in" : "out",
+ usb_pipeendpoint(urb->pipe),
+ usb_pipein(urb->pipe) ? "in" : "out",
urb->transfer_buffer_length,
urb->number_of_packets, urb->interval,
stream);
#endif

/* allocate ITDs w/o locking anything */
- status = itd_urb_transaction (stream, ehci, urb, mem_flags);
- if (unlikely (status < 0)) {
- ehci_dbg (ehci, "can't init itds\n");
+ status = itd_urb_transaction(stream, ehci, urb, mem_flags);
+ if (unlikely(status < 0)) {
+ ehci_dbg(ehci, "can't init itds\n");
goto done;
}

/* schedule ... need to lock */
- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);
if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
status = -ESHUTDOWN;
goto done_not_linked;
@@ -1984,7 +1985,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
goto done_not_linked;
status = iso_stream_schedule(ehci, urb, stream);
if (likely(status == 0)) {
- itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
+ itd_link_urb(ehci, urb, ehci->periodic_size << 3, stream);
} else if (status > 0) {
status = 0;
ehci_urb_done(ehci, urb, 0);
@@ -1992,7 +1993,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
}
done_not_linked:
- spin_unlock_irqrestore (&ehci->lock, flags);
+ spin_unlock_irqrestore(&ehci->lock, flags);
done:
return status;
}
@@ -2022,13 +2023,13 @@ sitd_sched_init(
* when we fit new sitds into the schedule.
*/
for (i = 0; i < urb->number_of_packets; i++) {
- struct ehci_iso_packet *packet = &iso_sched->packet [i];
+ struct ehci_iso_packet *packet = &iso_sched->packet[i];
unsigned length;
dma_addr_t buf;
u32 trans;

- length = urb->iso_frame_desc [i].length & 0x03ff;
- buf = dma + urb->iso_frame_desc [i].offset;
+ length = urb->iso_frame_desc[i].length & 0x03ff;
+ buf = dma + urb->iso_frame_desc[i].offset;

trans = SITD_STS_ACTIVE;
if (((i + 1) == urb->number_of_packets)
@@ -2054,7 +2055,7 @@ sitd_sched_init(
}

static int
-sitd_urb_transaction (
+sitd_urb_transaction(
struct ehci_iso_stream *stream,
struct ehci_hcd *ehci,
struct urb *urb,
@@ -2067,14 +2068,14 @@ sitd_urb_transaction (
struct ehci_iso_sched *iso_sched;
unsigned long flags;

- iso_sched = iso_sched_alloc (urb->number_of_packets, mem_flags);
+ iso_sched = iso_sched_alloc(urb->number_of_packets, mem_flags);
if (iso_sched == NULL)
return -ENOMEM;

sitd_sched_init(ehci, iso_sched, stream, urb);

/* allocate/init sITDs */
- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);
for (i = 0; i < urb->number_of_packets; i++) {

/* NOTE: for now, we don't try to handle wraparound cases
@@ -2091,14 +2092,14 @@ sitd_urb_transaction (
struct ehci_sitd, sitd_list);
if (sitd->frame == ehci->now_frame)
goto alloc_sitd;
- list_del (&sitd->sitd_list);
+ list_del(&sitd->sitd_list);
sitd_dma = sitd->sitd_dma;
} else {
alloc_sitd:
- spin_unlock_irqrestore (&ehci->lock, flags);
- sitd = dma_pool_alloc (ehci->sitd_pool, mem_flags,
+ spin_unlock_irqrestore(&ehci->lock, flags);
+ sitd = dma_pool_alloc(ehci->sitd_pool, mem_flags,
&sitd_dma);
- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);
if (!sitd) {
iso_sched_free(stream, iso_sched);
spin_unlock_irqrestore(&ehci->lock, flags);
@@ -2106,17 +2107,17 @@ sitd_urb_transaction (
}
}

- memset (sitd, 0, sizeof *sitd);
+ memset(sitd, 0, sizeof *sitd);
sitd->sitd_dma = sitd_dma;
sitd->frame = NO_FRAME;
- list_add (&sitd->sitd_list, &iso_sched->td_list);
+ list_add(&sitd->sitd_list, &iso_sched->td_list);
}

/* temporarily store schedule info in hcpriv */
urb->hcpriv = iso_sched;
urb->error_count = 0;

- spin_unlock_irqrestore (&ehci->lock, flags);
+ spin_unlock_irqrestore(&ehci->lock, flags);
return 0;
}

@@ -2131,7 +2132,7 @@ sitd_patch(
unsigned index
)
{
- struct ehci_iso_packet *uf = &iso_sched->packet [index];
+ struct ehci_iso_packet *uf = &iso_sched->packet[index];
u64 bufp;

sitd->hw_next = EHCI_LIST_END(ehci);
@@ -2152,14 +2153,14 @@ sitd_patch(
}

static inline void
-sitd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_sitd *sitd)
+sitd_link(struct ehci_hcd *ehci, unsigned frame, struct ehci_sitd *sitd)
{
/* note: sitd ordering could matter (CSPLIT then SSPLIT) */
- sitd->sitd_next = ehci->pshadow [frame];
- sitd->hw_next = ehci->periodic [frame];
- ehci->pshadow [frame].sitd = sitd;
+ sitd->sitd_next = ehci->pshadow[frame];
+ sitd->hw_next = ehci->periodic[frame];
+ ehci->pshadow[frame].sitd = sitd;
sitd->frame = frame;
- wmb ();
+ wmb();
ehci->periodic[frame] = cpu_to_hc32(ehci, sitd->sitd_dma | Q_TYPE_SITD);
}

@@ -2196,13 +2197,13 @@ static void sitd_link_urb(
packet++) {

/* ASSERT: we have all necessary sitds */
- BUG_ON (list_empty (&sched->td_list));
+ BUG_ON(list_empty(&sched->td_list));

/* ASSERT: no itds for this endpoint in this frame */

- sitd = list_entry (sched->td_list.next,
+ sitd = list_entry(sched->td_list.next,
struct ehci_sitd, sitd_list);
- list_move_tail (&sitd->sitd_list, &stream->td_list);
+ list_move_tail(&sitd->sitd_list, &stream->td_list);
sitd->stream = stream;
sitd->urb = urb;

@@ -2215,7 +2216,7 @@ static void sitd_link_urb(
stream->next_uframe = next_uframe & (mod - 1);

/* don't need that schedule data any more */
- iso_sched_free (stream, sched);
+ iso_sched_free(stream, sched);
urb->hcpriv = stream;

++ehci->isoc_count;
@@ -2248,14 +2249,14 @@ static bool sitd_complete(struct ehci_hcd *ehci, struct ehci_sitd *sitd)
bool retval = false;

urb_index = sitd->index;
- desc = &urb->iso_frame_desc [urb_index];
+ desc = &urb->iso_frame_desc[urb_index];
t = hc32_to_cpup(ehci, &sitd->hw_results);

/* report transfer status */
if (unlikely(t & SITD_ERRS)) {
urb->error_count++;
if (t & SITD_STS_DBE)
- desc->status = usb_pipein (urb->pipe)
+ desc->status = usb_pipein(urb->pipe)
? -ENOSR /* hc couldn't read */
: -ECOMM; /* hc couldn't write */
else if (t & SITD_STS_BABBLE)
@@ -2316,7 +2317,7 @@ done:
}


-static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
+static int sitd_submit(struct ehci_hcd *ehci, struct urb *urb,
gfp_t mem_flags)
{
int status = -EINVAL;
@@ -2324,35 +2325,35 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
struct ehci_iso_stream *stream;

/* Get iso_stream head */
- stream = iso_stream_find (ehci, urb);
+ stream = iso_stream_find(ehci, urb);
if (stream == NULL) {
- ehci_dbg (ehci, "can't get iso stream\n");
+ ehci_dbg(ehci, "can't get iso stream\n");
return -ENOMEM;
}
if (urb->interval != stream->ps.period) {
- ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
+ ehci_dbg(ehci, "can't change iso interval %d --> %d\n",
stream->ps.period, urb->interval);
goto done;
}

#ifdef EHCI_URB_TRACE
- ehci_dbg (ehci,
+ ehci_dbg(ehci,
"submit %p dev%s ep%d%s-iso len %d\n",
urb, urb->dev->devpath,
- usb_pipeendpoint (urb->pipe),
- usb_pipein (urb->pipe) ? "in" : "out",
+ usb_pipeendpoint(urb->pipe),
+ usb_pipein(urb->pipe) ? "in" : "out",
urb->transfer_buffer_length);
#endif

/* allocate SITDs */
- status = sitd_urb_transaction (stream, ehci, urb, mem_flags);
+ status = sitd_urb_transaction(stream, ehci, urb, mem_flags);
if (status < 0) {
- ehci_dbg (ehci, "can't init sitds\n");
+ ehci_dbg(ehci, "can't init sitds\n");
goto done;
}

/* schedule ... need to lock */
- spin_lock_irqsave (&ehci->lock, flags);
+ spin_lock_irqsave(&ehci->lock, flags);
if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
status = -ESHUTDOWN;
goto done_not_linked;
@@ -2362,7 +2363,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
goto done_not_linked;
status = iso_stream_schedule(ehci, urb, stream);
if (likely(status == 0)) {
- sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
+ sitd_link_urb(ehci, urb, ehci->periodic_size << 3, stream);
} else if (status > 0) {
status = 0;
ehci_urb_done(ehci, urb, 0);
@@ -2370,7 +2371,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
}
done_not_linked:
- spin_unlock_irqrestore (&ehci->lock, flags);
+ spin_unlock_irqrestore(&ehci->lock, flags);
done:
return status;
}
--
2.6.3

2015-12-12 01:20:46

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 06/10] usb: host: ehci-sched: remove useless else branch

This patch removes an useless else branch after a break, reducing one
indent block.

Tested by compilation only.
Caught by checkpatch.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index a42ea4d..81f3dfea 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -296,10 +296,9 @@ static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
if (x <= 125) {
budget_line[uf] = x;
break;
- } else {
- budget_line[uf] = 125;
- x -= 125;
}
+ budget_line[uf] = 125;
+ x -= 125;
}
}
}
--
2.6.3

2015-12-12 01:20:48

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 07/10] usb: host: ehci-sched: use C89-style comments

This patch changes comments conforming coding style.

Caught by checkpatch.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 81f3dfea..cf203d6 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -52,7 +52,7 @@ periodic_next_shadow(struct ehci_hcd *ehci, union ehci_shadow *periodic,
return &periodic->fstn->fstn_next;
case Q_TYPE_ITD:
return &periodic->itd->itd_next;
- // case Q_TYPE_SITD:
+ /* case Q_TYPE_SITD: */
default:
return &periodic->sitd->sitd_next;
}
@@ -491,7 +491,7 @@ static int tt_no_collision(
type = Q_NEXT_TYPE(ehci, here.sitd->hw_next);
here = here.sitd->sitd_next;
continue;
- // case Q_TYPE_FSTN:
+ /* case Q_TYPE_FSTN: */
default:
ehci_dbg(ehci,
"periodic frame %d bogus type %d\n",
@@ -784,7 +784,7 @@ static int check_period(
return 0;
}

- // success!
+ /* success! */
return 1;
}

@@ -1254,7 +1254,7 @@ iso_sched_free(
{
if (!iso_sched)
return;
- // caller must hold ehci->lock!
+ /* caller must hold ehci->lock! */
list_splice(&iso_sched->td_list, &stream->free_list);
kfree(iso_sched);
}
@@ -1715,7 +1715,7 @@ itd_patch(
struct ehci_iso_packet *uf = &iso_sched->packet[index];
unsigned pg = itd->pg;

- // BUG_ON (pg == 6 && uf->cross);
+ /* BUG_ON(pg == 6 && uf->cross); */

uframe &= 0x07;
itd->index[uframe] = index;
@@ -1792,7 +1792,7 @@ static void itd_link_urb(
packet < urb->number_of_packets;) {
if (itd == NULL) {
/* ASSERT: we have all necessary itds */
- // BUG_ON (list_empty (&iso_sched->td_list));
+ /* BUG_ON(list_empty(&iso_sched->td_list)); */

/* ASSERT: no itds for this endpoint in this uframe */

@@ -1894,9 +1894,10 @@ static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)
if (likely((urb_index + 1) != urb->number_of_packets))
goto done;

- /* ASSERT: it's really the last itd for this urb
- list_for_each_entry (itd, &stream->td_list, itd_list)
- BUG_ON (itd->urb == urb);
+ /*
+ * ASSERT: it's really the last itd for this urb
+ * list_for_each_entry (itd, &stream->td_list, itd_list)
+ * BUG_ON(itd->urb == urb);
*/

/* give urb back to the driver; completion often (re)submits */
@@ -2275,9 +2276,10 @@ static bool sitd_complete(struct ehci_hcd *ehci, struct ehci_sitd *sitd)
if ((urb_index + 1) != urb->number_of_packets)
goto done;

- /* ASSERT: it's really the last sitd for this urb
- list_for_each_entry (sitd, &stream->td_list, sitd_list)
- BUG_ON (sitd->urb == urb);
+ /*
+ * ASSERT: it's really the last sitd for this urb
+ * list_for_each_entry (sitd, &stream->td_list, sitd_list)
+ * BUG_ON(sitd->urb == urb);
*/

/* give urb back to the driver; completion often (re)submits */
--
2.6.3

2015-12-12 01:20:58

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 08/10] usb: host: ehci-sched: add line after declarations

This patch adds a blank line after declarations.

Caught by checkpatch.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index cf203d6..2e7d20f 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -330,6 +330,7 @@ static int __maybe_unused same_tt(struct usb_device *dev1,
static inline unsigned char tt_start_uframe(struct ehci_hcd *ehci, __hc32 mask)
{
unsigned char smask = hc32_to_cpu(ehci, mask) & QH_SMASK;
+
if (!smask) {
ehci_err(ehci, "invalid empty smask!\n");
/* uframe 7 can't have bw so this will indicate failure */
@@ -345,6 +346,7 @@ max_tt_usecs[] = { 125, 125, 125, 125, 125, 125, 30, 0 };
static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
{
int i;
+
for (i = 0; i < 7; i++) {
if (max_tt_usecs[i] < tt_usecs[i]) {
tt_usecs[i+1] += tt_usecs[i] - max_tt_usecs[i];
--
2.6.3

2015-12-12 01:21:04

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 09/10] usb: host: ehci-sched: use sizeof operator with parens

This patch adds parens to sizeof operator uses.

Tested by compilation only.
Caught by checkpatch.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 2e7d20f..1dc1d5c 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1028,7 +1028,7 @@ iso_stream_alloc(gfp_t mem_flags)
{
struct ehci_iso_stream *stream;

- stream = kzalloc(sizeof *stream, mem_flags);
+ stream = kzalloc(sizeof(*stream), mem_flags);
if (likely(stream != NULL)) {
INIT_LIST_HEAD(&stream->td_list);
INIT_LIST_HEAD(&stream->free_list);
@@ -1196,7 +1196,7 @@ static struct ehci_iso_sched *
iso_sched_alloc(unsigned packets, gfp_t mem_flags)
{
struct ehci_iso_sched *iso_sched;
- int size = sizeof *iso_sched;
+ int size = sizeof(*iso_sched);

size += packets * sizeof(struct ehci_iso_packet);
iso_sched = kzalloc(size, mem_flags);
@@ -1315,7 +1315,7 @@ itd_urb_transaction(
}
}

- memset(itd, 0, sizeof *itd);
+ memset(itd, 0, sizeof(*itd));
itd->itd_dma = itd_dma;
itd->frame = NO_FRAME;
list_add(&itd->itd_list, &sched->td_list);
@@ -2109,7 +2109,7 @@ sitd_urb_transaction(
}
}

- memset(sitd, 0, sizeof *sitd);
+ memset(sitd, 0, sizeof(*sitd));
sitd->sitd_dma = sitd_dma;
sitd->frame = NO_FRAME;
list_add(&sitd->sitd_list, &iso_sched->td_list);
--
2.6.3

2015-12-12 01:21:10

by Geyslan G. Bem

[permalink] [raw]
Subject: [PATCH 10/10] usb: host: ehci-sched: remove unnecessary braces

This patch removes unnecessary braces in single statement blocks at the
same time as replaces the if statement with a ternary conditional.

Tested by compilation only.
Caught by checkpatch.

Signed-off-by: Geyslan G. Bem <[email protected]>
---
drivers/usb/host/ehci-sched.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 1dc1d5c..f6e828a 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1060,11 +1060,7 @@ iso_stream_init(
epnum = usb_pipeendpoint(urb->pipe);
is_input = usb_pipein(urb->pipe) ? USB_DIR_IN : 0;
maxp = usb_endpoint_maxp(&urb->ep->desc);
- if (is_input) {
- buf1 = (1 << 11);
- } else {
- buf1 = 0;
- }
+ buf1 = (is_input) ? (1 << 11) : 0;

/* knows about ITD vs SITD */
if (dev->speed == USB_SPEED_HIGH) {
--
2.6.3

2015-12-12 14:48:30

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH 03/10] usb: host: ehci-sched: remove useless assignments

Hello.

On 12/12/2015 4:19 AM, Geyslan G. Bem wrote:

> This patch removes useless assignments.

Initializers, you mean?

> Tested by compilation only.
> Caught by cppcheck.
>
> Signed-off-by: Geyslan G. Bem <[email protected]>

[...]

MBR, Sergei

2015-12-12 14:50:28

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH 10/10] usb: host: ehci-sched: remove unnecessary braces

On 12/12/2015 4:19 AM, Geyslan G. Bem wrote:

> This patch removes unnecessary braces in single statement blocks at the
> same time as replaces the if statement with a ternary conditional.
>
> Tested by compilation only.
> Caught by checkpatch.
>
> Signed-off-by: Geyslan G. Bem <[email protected]>
> ---
> drivers/usb/host/ehci-sched.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index 1dc1d5c..f6e828a 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -1060,11 +1060,7 @@ iso_stream_init(
> epnum = usb_pipeendpoint(urb->pipe);
> is_input = usb_pipein(urb->pipe) ? USB_DIR_IN : 0;
> maxp = usb_endpoint_maxp(&urb->ep->desc);
> - if (is_input) {
> - buf1 = (1 << 11);
> - } else {
> - buf1 = 0;
> - }
> + buf1 = (is_input) ? (1 << 11) : 0;

Parens not needed, especially the first ones.

[...]

MBR, Sergei

2015-12-12 15:43:38

by Geyslan G. Bem

[permalink] [raw]
Subject: Re: [PATCH 03/10] usb: host: ehci-sched: remove useless assignments

2015-12-12 11:48 GMT-03:00 Sergei Shtylyov <[email protected]>:
> Hello.
>
> On 12/12/2015 4:19 AM, Geyslan G. Bem wrote:
>
>> This patch removes useless assignments.
>
>
> Initializers, you mean?
You're right. Fixing.

>
>> Tested by compilation only.
>> Caught by cppcheck.
>>
>> Signed-off-by: Geyslan G. Bem <[email protected]>
>
>
> [...]
>
> MBR, Sergei
>



--
Regards,

Geyslan G. Bem
hackingbits.com

2015-12-12 15:48:44

by Geyslan G. Bem

[permalink] [raw]
Subject: Re: [PATCH 10/10] usb: host: ehci-sched: remove unnecessary braces

2015-12-12 11:50 GMT-03:00 Sergei Shtylyov <[email protected]>:
> On 12/12/2015 4:19 AM, Geyslan G. Bem wrote:
>
>> This patch removes unnecessary braces in single statement blocks at the
>> same time as replaces the if statement with a ternary conditional.
>>
>> Tested by compilation only.
>> Caught by checkpatch.
>>
>> Signed-off-by: Geyslan G. Bem <[email protected]>
>> ---
>> drivers/usb/host/ehci-sched.c | 6 +-----
>> 1 file changed, 1 insertion(+), 5 deletions(-)
>>
>> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
>> index 1dc1d5c..f6e828a 100644
>> --- a/drivers/usb/host/ehci-sched.c
>> +++ b/drivers/usb/host/ehci-sched.c
>> @@ -1060,11 +1060,7 @@ iso_stream_init(
>> epnum = usb_pipeendpoint(urb->pipe);
>> is_input = usb_pipein(urb->pipe) ? USB_DIR_IN : 0;
>> maxp = usb_endpoint_maxp(&urb->ep->desc);
>> - if (is_input) {
>> - buf1 = (1 << 11);
>> - } else {
>> - buf1 = 0;
>> - }
>> + buf1 = (is_input) ? (1 << 11) : 0;
>
>
> Parens not needed, especially the first ones.
Right. Removing them.

After changing those patches should I resend the whole bunch with v2
tag, or only the changed ones?

And about a sequential patch that I sent for the same file, is it
better leave it out or add it to the bunch?
[PATCH] usb: host: ehci-sched: silence checkpatch warning

Tks.

>
> [...]
>
> MBR, Sergei
>



--
Regards,

Geyslan G. Bem
hackingbits.com

2015-12-12 16:15:36

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH 01/10] usb: host: ehci-sched: refactor scan_isoc function

On Fri, 11 Dec 2015, Geyslan G. Bem wrote:

> This patch removes an infinite 'for' loop and makes use of the already
> existing 'restart' tag instead, reducing one leading tab.
>
> The comments and code were corrected conforming coding style.
>
> Tested by compilation only.
> Caught by checkpatch:
> WARNING: Too many leading tabs - consider code refactoring
>
> Signed-off-by: Geyslan G. Bem <[email protected]>
> ---
> drivers/usb/host/ehci-sched.c | 203 ++++++++++++++++++++++--------------------
> 1 file changed, 104 insertions(+), 99 deletions(-)
>
> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
> index f9a3327..86b2484 100644
> --- a/drivers/usb/host/ehci-sched.c
> +++ b/drivers/usb/host/ehci-sched.c
> @@ -2383,6 +2383,9 @@ static void scan_isoc(struct ehci_hcd *ehci)
> unsigned fmask = ehci->periodic_size - 1;
> bool modified, live;
>
> + union ehci_shadow q, *q_p;
> + __hc32 type, *hw_p;

These new declarations should line up with the ones above. And there
shouldn't be a blank line between.

> + while (q.ptr != NULL) {
> + switch (hc32_to_cpu(ehci, type)) {
> + case Q_TYPE_ITD:
> + /*
> + * If this ITD is still active, leave it for
> + * later processing ... check the next entry.
> + * No need to check for activity unless the
> + * frame is current.
> + */
> + if (frame == now_frame && live) {
> + rmb();
> + for (uf = 0; uf < 8; uf++) {
> + if (q.itd->hw_transaction[uf] &
> + ITD_ACTIVE(ehci))

The style used in this source file does not align continuation lines
with open parens on the line above. Instead, the continuation lines
are indented by 2 extra tabs (or maybe 1 extra if 2 would pushd them
beyond 80 characters).

> + if (uf < 8) {
> + q_p = &q.itd->itd_next;
> + hw_p = &q.itd->hw_next;
> type = Q_NEXT_TYPE(ehci,
> - q.sitd->hw_next);
> + q.itd->hw_next);

Ditto.

> + /*
> + * Take finished ITDs out of the schedule
> + * and process them: recycle, maybe report
> + * URB completion. HC won't cache the
> + * pointer for much longer, if at all.
> + */
> + *q_p = q.itd->itd_next;
> + if (!ehci->use_dummy_qh ||
> + q.itd->hw_next != EHCI_LIST_END(ehci))

Ditto.

> + *hw_p = q.itd->hw_next;
> + else
> + *hw_p = cpu_to_hc32(ehci,
> + ehci->dummy->qh_dma);

Ditto.

> + case Q_TYPE_SITD:
> + /*
> + * If this SITD is still active, leave it for
> + * later processing ... check the next entry.
> + * No need to check for activity unless the
> + * frame is current.
> + */
> + if (((frame == now_frame) ||
> + (((frame + 1) & fmask) == now_frame))
> + && live
> + && (q.sitd->hw_results &
> + SITD_ACTIVE(ehci))) {

Although these lines didn't follow the style used in the rest of the
file, they should do so now.

> +
> + q_p = &q.sitd->sitd_next;
> + hw_p = &q.sitd->hw_next;
> + type = Q_NEXT_TYPE(ehci,
> + q.sitd->hw_next);

Ditto

> + * Take finished SITDs out of the schedule
> + * and process them: recycle, maybe report
> + * URB completion.
> + */
> + *q_p = q.sitd->sitd_next;
> + if (!ehci->use_dummy_qh ||
> + q.sitd->hw_next != EHCI_LIST_END(ehci))

Ditto.

> + *hw_p = q.sitd->hw_next;
> + else
> + *hw_p = cpu_to_hc32(ehci,
> + ehci->dummy->qh_dma);

Ditto.

> + type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
> + wmb();
> + modified = sitd_complete(ehci, q.sitd);
> + q = *q_p;
> break;
> + default:
> + ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
> + type, frame, q.ptr);

Ditto.

Alan Stern

2015-12-12 16:52:56

by Geyslan G. Bem

[permalink] [raw]
Subject: Re: [PATCH 01/10] usb: host: ehci-sched: refactor scan_isoc function

2015-12-12 13:15 GMT-03:00 Alan Stern <[email protected]>:
> On Fri, 11 Dec 2015, Geyslan G. Bem wrote:
>
>> This patch removes an infinite 'for' loop and makes use of the already
>> existing 'restart' tag instead, reducing one leading tab.
>>
>> The comments and code were corrected conforming coding style.
>>
>> Tested by compilation only.
>> Caught by checkpatch:
>> WARNING: Too many leading tabs - consider code refactoring
>>
>> Signed-off-by: Geyslan G. Bem <[email protected]>
>> ---
>> drivers/usb/host/ehci-sched.c | 203 ++++++++++++++++++++++--------------------
>> 1 file changed, 104 insertions(+), 99 deletions(-)
>>
>> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
>> index f9a3327..86b2484 100644
>> --- a/drivers/usb/host/ehci-sched.c
>> +++ b/drivers/usb/host/ehci-sched.c
>> @@ -2383,6 +2383,9 @@ static void scan_isoc(struct ehci_hcd *ehci)
>> unsigned fmask = ehci->periodic_size - 1;
>> bool modified, live;
>>
>> + union ehci_shadow q, *q_p;
>> + __hc32 type, *hw_p;
>
> These new declarations should line up with the ones above. And there
> shouldn't be a blank line between.
Ok, I'll fix it.

>
>> + while (q.ptr != NULL) {
>> + switch (hc32_to_cpu(ehci, type)) {
>> + case Q_TYPE_ITD:
>> + /*
>> + * If this ITD is still active, leave it for
>> + * later processing ... check the next entry.
>> + * No need to check for activity unless the
>> + * frame is current.
>> + */
>> + if (frame == now_frame && live) {
>> + rmb();
>> + for (uf = 0; uf < 8; uf++) {
>> + if (q.itd->hw_transaction[uf] &
>> + ITD_ACTIVE(ehci))
>
> The style used in this source file does not align continuation lines
> with open parens on the line above. Instead, the continuation lines
> are indented by 2 extra tabs (or maybe 1 extra if 2 would pushd them
> beyond 80 characters).
My Emacs is configured for linux indentation. I'll fix it manually. Or
have you a ready lisp for this style? :-)
Is there a doc like the Documentation/CodingStyle with this different rules?

>
>> + if (uf < 8) {
>> + q_p = &q.itd->itd_next;
>> + hw_p = &q.itd->hw_next;
>> type = Q_NEXT_TYPE(ehci,
>> - q.sitd->hw_next);
>> + q.itd->hw_next);
>
> Ditto.
>
>> + /*
>> + * Take finished ITDs out of the schedule
>> + * and process them: recycle, maybe report
>> + * URB completion. HC won't cache the
>> + * pointer for much longer, if at all.
>> + */
>> + *q_p = q.itd->itd_next;
>> + if (!ehci->use_dummy_qh ||
>> + q.itd->hw_next != EHCI_LIST_END(ehci))
>
> Ditto.
>
>> + *hw_p = q.itd->hw_next;
>> + else
>> + *hw_p = cpu_to_hc32(ehci,
>> + ehci->dummy->qh_dma);
>
> Ditto.
>
>> + case Q_TYPE_SITD:
>> + /*
>> + * If this SITD is still active, leave it for
>> + * later processing ... check the next entry.
>> + * No need to check for activity unless the
>> + * frame is current.
>> + */
>> + if (((frame == now_frame) ||
>> + (((frame + 1) & fmask) == now_frame))
>> + && live
>> + && (q.sitd->hw_results &
>> + SITD_ACTIVE(ehci))) {
>
> Although these lines didn't follow the style used in the rest of the
> file, they should do so now.
Ok.

>
>> +
>> + q_p = &q.sitd->sitd_next;
>> + hw_p = &q.sitd->hw_next;
>> + type = Q_NEXT_TYPE(ehci,
>> + q.sitd->hw_next);
>
> Ditto
>
>> + * Take finished SITDs out of the schedule
>> + * and process them: recycle, maybe report
>> + * URB completion.
>> + */
>> + *q_p = q.sitd->sitd_next;
>> + if (!ehci->use_dummy_qh ||
>> + q.sitd->hw_next != EHCI_LIST_END(ehci))
>
> Ditto.
>
>> + *hw_p = q.sitd->hw_next;
>> + else
>> + *hw_p = cpu_to_hc32(ehci,
>> + ehci->dummy->qh_dma);
>
> Ditto.
>
>> + type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
>> + wmb();
>> + modified = sitd_complete(ehci, q.sitd);
>> + q = *q_p;
>> break;
>> + default:
>> + ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
>> + type, frame, q.ptr);
>
> Ditto.
>
> Alan Stern
>



--
Regards,

Geyslan G. Bem
hackingbits.com

2015-12-12 17:11:40

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH 01/10] usb: host: ehci-sched: refactor scan_isoc function

On Sat, 12 Dec 2015, Geyslan G. Bem wrote:

> >> + if (q.itd->hw_transaction[uf] &
> >> + ITD_ACTIVE(ehci))
> >
> > The style used in this source file does not align continuation lines
> > with open parens on the line above. Instead, the continuation lines
> > are indented by 2 extra tabs (or maybe 1 extra if 2 would pushd them
> > beyond 80 characters).
> My Emacs is configured for linux indentation. I'll fix it manually. Or
> have you a ready lisp for this style? :-)

I don't.

> Is there a doc like the Documentation/CodingStyle with this different rules?

Not as far as I know.

Alan Stern