Re: [PATCH] staging: rts5208: clear alignment style issues

From: Joe Perches
Date: Sat Aug 01 2020 - 21:46:24 EST


On Sun, 2020-08-02 at 00:00 +0300, Tomer Samara wrote:
> Clear checkpatch alignment style issues in rtsx_transport.c.
> CHECK: Alignment should match open parenthesis
[]
> diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
[]
> @@ -678,7 +678,7 @@ static int rtsx_transfer_buf(struct rtsx_chip *chip, u8 card, void *buf,
>
> /* Wait for TRANS_OK_INT */
> timeleft = wait_for_completion_interruptible_timeout(&trans_done,
> - msecs_to_jiffies(timeout));
> + msecs_to_jiffies(timeout));
> if (timeleft <= 0) {
> dev_dbg(rtsx_dev(chip), "Timeout (%s %d)\n",
> __func__, __LINE__);

Always try to improve the code rather than just
shut up checkpatch warnings.

Perhaps it's more sensible to centralize the uses of
wait_for_completion_interruptible_timeout.

Something like:
---
drivers/staging/rts5208/rtsx_transport.c | 36 +++++++++++++-------------------
1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
index 5f1eefe80f1e..269ff1be7cba 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -222,12 +222,18 @@ void rtsx_send_cmd_no_wait(struct rtsx_chip *chip)
rtsx_writel(chip, RTSX_HCBCTLR, val);
}

+static inline bool rtsx_wait(struct completion *comp, int timeout)
+{
+ unsigned long t = msecs_to_jiffies(timeout);
+
+ return wait_for_completion_interruptible_timeout(comp, t) > 0;
+}
+
int rtsx_send_cmd(struct rtsx_chip *chip, u8 card, int timeout)
{
struct rtsx_dev *rtsx = chip->rtsx;
struct completion trans_done;
u32 val = BIT(31);
- long timeleft;
int err = 0;

if (card == SD_CARD)
@@ -257,9 +263,8 @@ int rtsx_send_cmd(struct rtsx_chip *chip, u8 card, int timeout)
spin_unlock_irq(&rtsx->reg_lock);

/* Wait for TRANS_OK_INT */
- timeleft = wait_for_completion_interruptible_timeout(
- &trans_done, msecs_to_jiffies(timeout));
- if (timeleft <= 0) {
+
+ if (!rtsx_wait(&trans_done, timeout)) {
dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n",
chip->int_reg);
err = -ETIMEDOUT;
@@ -322,7 +327,6 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,
u8 dir;
int sg_cnt, i, resid;
int err = 0;
- long timeleft;
struct scatterlist *sg_ptr;
u32 val = TRIG_DMA;

@@ -419,9 +423,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,

spin_unlock_irq(&rtsx->reg_lock);

- timeleft = wait_for_completion_interruptible_timeout(
- &trans_done, msecs_to_jiffies(timeout));
- if (timeleft <= 0) {
+ if (!rtsx_wait(&trans_done, timeout)) {
dev_dbg(rtsx_dev(chip), "Timeout (%s %d)\n",
__func__, __LINE__);
dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n",
@@ -443,9 +445,7 @@ static int rtsx_transfer_sglist_adma_partial(struct rtsx_chip *chip, u8 card,
if (rtsx->trans_result == TRANS_NOT_READY) {
init_completion(&trans_done);
spin_unlock_irq(&rtsx->reg_lock);
- timeleft = wait_for_completion_interruptible_timeout(
- &trans_done, msecs_to_jiffies(timeout));
- if (timeleft <= 0) {
+ if (!rtsx_wait(&trans_done, timeout)) {
dev_dbg(rtsx_dev(chip), "Timeout (%s %d)\n",
__func__, __LINE__);
dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n",
@@ -486,7 +486,6 @@ static int rtsx_transfer_sglist_adma(struct rtsx_chip *chip, u8 card,
u8 dir;
int buf_cnt, i;
int err = 0;
- long timeleft;
struct scatterlist *sg_ptr;

if (!sg || (num_sg <= 0))
@@ -563,9 +562,7 @@ static int rtsx_transfer_sglist_adma(struct rtsx_chip *chip, u8 card,

spin_unlock_irq(&rtsx->reg_lock);

- timeleft = wait_for_completion_interruptible_timeout(
- &trans_done, msecs_to_jiffies(timeout));
- if (timeleft <= 0) {
+ if (!rtsx_wait(&trans_done, timeout)) {
dev_dbg(rtsx_dev(chip), "Timeout (%s %d)\n",
__func__, __LINE__);
dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n",
@@ -590,9 +587,7 @@ static int rtsx_transfer_sglist_adma(struct rtsx_chip *chip, u8 card,
if (rtsx->trans_result == TRANS_NOT_READY) {
init_completion(&trans_done);
spin_unlock_irq(&rtsx->reg_lock);
- timeleft = wait_for_completion_interruptible_timeout(
- &trans_done, msecs_to_jiffies(timeout));
- if (timeleft <= 0) {
+ if (!rtsx_wait(&trans_done, timeout)) {
dev_dbg(rtsx_dev(chip), "Timeout (%s %d)\n",
__func__, __LINE__);
dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n",
@@ -633,7 +628,6 @@ static int rtsx_transfer_buf(struct rtsx_chip *chip, u8 card, void *buf,
u8 dir;
int err = 0;
u32 val = BIT(31);
- long timeleft;

if (!buf || (len <= 0))
return -EIO;
@@ -677,9 +671,7 @@ static int rtsx_transfer_buf(struct rtsx_chip *chip, u8 card, void *buf,
spin_unlock_irq(&rtsx->reg_lock);

/* Wait for TRANS_OK_INT */
- timeleft = wait_for_completion_interruptible_timeout(&trans_done,
- msecs_to_jiffies(timeout));
- if (timeleft <= 0) {
+ if (!rtsx_wait(&trans_done, timeout)) {
dev_dbg(rtsx_dev(chip), "Timeout (%s %d)\n",
__func__, __LINE__);
dev_dbg(rtsx_dev(chip), "chip->int_reg = 0x%x\n",