Thread (39 messages) 39 messages, 7 authors, 2025-08-15

Re: [PATCH v3 4/5] net: rnpgbe: Add basic mbx_fw support

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2025-08-13 11:05:50
Also in: linux-doc, lkml

Hi Yibo,

On Wed, 13 Aug 2025 at 11:52, Yibo Dong [off-list ref] wrote:
On Tue, Aug 12, 2025 at 05:14:15PM +0100, Vadim Fedorenko wrote:
quoted
On 12/08/2025 10:39, Dong Yibo wrote:
quoted
Initialize basic mbx_fw ops, such as get_capability, reset phy
and so on.

Signed-off-by: Dong Yibo <dong100@mucse.com>
+static int mucse_fw_send_cmd_wait(struct mucse_hw *hw,
+                             struct mbx_fw_cmd_req *req,
+                             struct mbx_fw_cmd_reply *reply)
+{
+   int len = le16_to_cpu(req->datalen) + MBX_REQ_HDR_LEN;
+   int retry_cnt = 3;
+   int err;
+
+   err = mutex_lock_interruptible(&hw->mbx.lock);
+   if (err)
+           return err;
+   err = hw->mbx.ops->write_posted(hw, (u32 *)req,
+                                   L_WD(len));
+   if (err) {> +           mutex_unlock(&hw->mbx.lock);
+           return err;
+   }
it might look a bit cleaner if you add error label and have unlock code
once in the end of the function...
If it is more cleaner bellow?

static int mucse_fw_send_cmd_wait(struct mucse_hw *hw,
                                  struct mbx_fw_cmd_req *req,
                                  struct mbx_fw_cmd_reply *reply)
{
        int len = le16_to_cpu(req->datalen) + MBX_REQ_HDR_LEN;
        int retry_cnt = 3;
        int err;

        err = mutex_lock_interruptible(&hw->mbx.lock);
        if (err)
                return err;
        err = hw->mbx.ops->write_posted(hw, (u32 *)req,
                                        L_WD(len));
        if (err)
                goto quit;
        do {
                err = hw->mbx.ops->read_posted(hw, (u32 *)reply,
                                               L_WD(sizeof(*reply)));
                if (err)
                        goto quit;
        } while (--retry_cnt >= 0 && reply->opcode != req->opcode);

        mutex_unlock(&hw->mbx.lock);
        if (retry_cnt < 0)
                return -ETIMEDOUT;
        if (reply->error_code)
                return -EIO;
        return 0;
quit:
        mutex_unlock(&hw->mbx.lock);
        return err;
}
Or use scoped_cond_guard(mutex_intr, ...) { ... }?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help