]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: usblp: clean up assignment inside if conditions
authorDarshan Rathod <darshan.rathod@siqol.com>
Fri, 18 Jul 2025 09:10:45 +0000 (14:40 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Jul 2025 14:30:54 +0000 (16:30 +0200)
This patch cleans up a few cases where assignments were made
inside of if conditions, like

if ((rv = func()) < 0)

into two lines, to improve readability and be more in-line with
Linux kernel coding style. It also cleans up checkpatch warnings
like:

ERROR: do not use assignment in if condition

No functional change, just a style and maintainability fix.

Signed-off-by: Darshan Rathod <darshan.rathod@siqol.com>
Link: https://lore.kernel.org/r/20250718091045.264129-1-darshan.rathod@siqol.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/class/usblp.c

index e2527faa6592c9a6a02fa58537c796d20de3899b..acbefccbdb2a489f6bc81c63d626f16702eecbf8 100644 (file)
@@ -366,7 +366,8 @@ static int usblp_check_status(struct usblp *usblp, int err)
        int error;
 
        mutex_lock(&usblp->mut);
-       if ((error = usblp_read_status(usblp, usblp->statusbuf)) < 0) {
+       error = usblp_read_status(usblp, usblp->statusbuf);
+       if (error < 0) {
                mutex_unlock(&usblp->mut);
                printk_ratelimited(KERN_ERR
                                "usblp%d: error %d reading printer status\n",
@@ -751,14 +752,16 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
                rv = -EINTR;
                goto raise_biglock;
        }
-       if ((rv = usblp_wwait(usblp, !!(file->f_flags & O_NONBLOCK))) < 0)
+       rv = usblp_wwait(usblp, !!(file->f_flags & O_NONBLOCK));
+       if (rv < 0)
                goto raise_wait;
 
        while (writecount < count) {
                /*
                 * Step 1: Submit next block.
                 */
-               if ((transfer_length = count - writecount) > USBLP_BUF_SIZE)
+               transfer_length = count - writecount;
+               if (transfer_length > USBLP_BUF_SIZE)
                        transfer_length = USBLP_BUF_SIZE;
 
                rv = -ENOMEM;
@@ -776,7 +779,9 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
                spin_lock_irq(&usblp->lock);
                usblp->wcomplete = 0;
                spin_unlock_irq(&usblp->lock);
-               if ((rv = usb_submit_urb(writeurb, GFP_KERNEL)) < 0) {
+
+               rv = usb_submit_urb(writeurb, GFP_KERNEL);
+               if (rv < 0) {
                        usblp->wstatus = 0;
                        spin_lock_irq(&usblp->lock);
                        usblp->no_paper = 0;
@@ -857,9 +862,10 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
                goto done;
        }
 
-       if ((avail = usblp->rstatus) < 0) {
+       avail = usblp->rstatus;
+       if (avail < 0) {
                printk(KERN_ERR "usblp%d: error %d reading from printer\n",
-                   usblp->minor, (int)avail);
+                       usblp->minor, (int)avail);
                usblp_submit_read(usblp);
                count = -EIO;
                goto done;
@@ -872,7 +878,8 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t len, lo
                goto done;
        }
 
-       if ((usblp->readcount += count) == avail) {
+       usblp->readcount += count;
+       if (usblp->readcount == avail) {
                if (usblp_submit_read(usblp) < 0) {
                        /* We don't want to leak USB return codes into errno. */
                        if (count == 0)
@@ -973,7 +980,8 @@ static int usblp_rwait_and_lock(struct usblp *usblp, int nonblock)
                        break;
                }
                set_current_state(TASK_INTERRUPTIBLE);
-               if ((rc = usblp_rtest(usblp, nonblock)) < 0) {
+               rc = usblp_rtest(usblp, nonblock);
+               if (rc < 0) {
                        mutex_unlock(&usblp->mut);
                        break;
                }
@@ -1031,7 +1039,8 @@ static int usblp_submit_read(struct usblp *usblp)
        usblp->readcount = 0; /* XXX Why here? */
        usblp->rcomplete = 0;
        spin_unlock_irqrestore(&usblp->lock, flags);
-       if ((rc = usb_submit_urb(urb, GFP_KERNEL)) < 0) {
+       rc = usb_submit_urb(urb, GFP_KERNEL);
+       if (rc < 0) {
                dev_dbg(&usblp->intf->dev, "error submitting urb (%d)\n", rc);
                spin_lock_irqsave(&usblp->lock, flags);
                usblp->rstatus = rc;
@@ -1150,7 +1159,8 @@ static int usblp_probe(struct usb_interface *intf,
        /* Malloc device ID string buffer to the largest expected length,
         * since we can re-query it on an ioctl and a dynamic string
         * could change in length. */
-       if (!(usblp->device_id_string = kmalloc(USBLP_DEVICE_ID_SIZE, GFP_KERNEL))) {
+       usblp->device_id_string = kmalloc(USBLP_DEVICE_ID_SIZE, GFP_KERNEL);
+       if (!usblp->device_id_string) {
                retval = -ENOMEM;
                goto abort;
        }
@@ -1160,7 +1170,8 @@ static int usblp_probe(struct usb_interface *intf,
         * malloc both regardless of bidirectionality, because the
         * alternate setting can be changed later via an ioctl.
         */
-       if (!(usblp->readbuf = kmalloc(USBLP_BUF_SIZE_IN, GFP_KERNEL))) {
+       usblp->readbuf = kmalloc(USBLP_BUF_SIZE_IN, GFP_KERNEL);
+       if (!usblp->readbuf) {
                retval = -ENOMEM;
                goto abort;
        }