The function device_alloc_rx_buf does 2 things: allocating rx buffer
and initializing the rx descriptor's values. Split this function into
two, with each does one job.
This split is preparation for implementing correct out-of-memory error
handling.
Signed-off-by: Nam Cao <namcaov@gmail.com>
---
drivers/staging/vt6655/device_main.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index 79325a693857..27fe28156257 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -133,6 +133,7 @@ static int device_init_td1_ring(struct vnt_private *priv);
static int device_rx_srv(struct vnt_private *priv, unsigned int idx);
static int device_tx_srv(struct vnt_private *priv, unsigned int idx);
static bool device_alloc_rx_buf(struct vnt_private *, struct vnt_rx_desc *);
+static void device_init_rx_desc(struct vnt_private *priv, struct vnt_rx_desc *rd);
static void device_free_rx_buf(struct vnt_private *priv,
struct vnt_rx_desc *rd);
static void device_init_registers(struct vnt_private *priv);
@@ -615,6 +616,8 @@ static int device_init_rd0_ring(struct vnt_private *priv)
dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
ret = -ENOMEM;
goto err_free_rd;
+ } else {
+ device_init_rx_desc(priv, desc);
}
desc->next = &priv->aRD0Ring[(i + 1) % priv->opts.rx_descs0];
@@ -661,6 +664,8 @@ static int device_init_rd1_ring(struct vnt_private *priv)
dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
ret = -ENOMEM;
goto err_free_rd;
+ } else {
+ device_init_rx_desc(priv, desc);
}
desc->next = &priv->aRD1Ring[(i + 1) % priv->opts.rx_descs1];
@@ -838,7 +843,10 @@ static int device_rx_srv(struct vnt_private *priv, unsigned int idx)
dev_err(&priv->pcid->dev,
"can not allocate rx buf\n");
break;
+ } else {
+ device_init_rx_desc(priv, rd);
}
+
rd->rd0.owner = OWNED_BY_NIC;
}
@@ -865,15 +873,17 @@ static bool device_alloc_rx_buf(struct vnt_private *priv,
rd_info->skb = NULL;
return false;
}
+ return true;
+}
+static void device_init_rx_desc(struct vnt_private *priv, struct vnt_rx_desc *rd)
+{
*((unsigned int *)&rd->rd0) = 0; /* FIX cast */
rd->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
rd->rd0.owner = OWNED_BY_NIC;
rd->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
- rd->buff_addr = cpu_to_le32(rd_info->skb_dma);
-
- return true;
+ rd->buff_addr = cpu_to_le32(rd->rd_info->skb_dma);
}
static void device_free_rx_buf(struct vnt_private *priv,
--
2.25.1
On Thu, Sep 15, 2022 at 10:29:34PM +0200, Nam Cao wrote:
> The function device_alloc_rx_buf does 2 things: allocating rx buffer
> and initializing the rx descriptor's values. Split this function into
> two, with each does one job.
>
> This split is preparation for implementing correct out-of-memory error
> handling.
>
> Signed-off-by: Nam Cao <namcaov@gmail.com>
> ---
> drivers/staging/vt6655/device_main.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
> index 79325a693857..27fe28156257 100644
> --- a/drivers/staging/vt6655/device_main.c
> +++ b/drivers/staging/vt6655/device_main.c
> @@ -133,6 +133,7 @@ static int device_init_td1_ring(struct vnt_private *priv);
> static int device_rx_srv(struct vnt_private *priv, unsigned int idx);
> static int device_tx_srv(struct vnt_private *priv, unsigned int idx);
> static bool device_alloc_rx_buf(struct vnt_private *, struct vnt_rx_desc *);
> +static void device_init_rx_desc(struct vnt_private *priv, struct vnt_rx_desc *rd);
> static void device_free_rx_buf(struct vnt_private *priv,
> struct vnt_rx_desc *rd);
> static void device_init_registers(struct vnt_private *priv);
> @@ -615,6 +616,8 @@ static int device_init_rd0_ring(struct vnt_private *priv)
> dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
> ret = -ENOMEM;
> goto err_free_rd;
> + } else {
> + device_init_rx_desc(priv, desc);
> }
None of these else statements make sense. It should be:
ret = -ENOMEM;
goto err_free_rd;
}
device_init_rx_desc(priv, desc);
desc->next = &priv->aRD0Ring[(i + 1) % priv->opts.rx_descs0];
I haven't reviewed the patch totally. I don't understand why it's doing
this here instead of at the end. But then I don't understand why it
needs to be in a separate function at all.
This patch does not make sense. The commit description says that this
is a "preparation" patch. Maybe fold it in with patch 5? The rule is
"one thing per patch" not "half a thing per patch".
regards,
dan carpenter
On Mon, Sep 19, 2022 at 12:36:05PM +0300, Dan Carpenter wrote:
> On Thu, Sep 15, 2022 at 10:29:34PM +0200, Nam Cao wrote:
> > The function device_alloc_rx_buf does 2 things: allocating rx buffer
> > and initializing the rx descriptor's values. Split this function into
> > two, with each does one job.
> >
> > This split is preparation for implementing correct out-of-memory error
> > handling.
> >
> > Signed-off-by: Nam Cao <namcaov@gmail.com>
> > ---
> > drivers/staging/vt6655/device_main.c | 16 +++++++++++++---
> > 1 file changed, 13 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
> > index 79325a693857..27fe28156257 100644
> > --- a/drivers/staging/vt6655/device_main.c
> > +++ b/drivers/staging/vt6655/device_main.c
> > @@ -133,6 +133,7 @@ static int device_init_td1_ring(struct vnt_private *priv);
> > static int device_rx_srv(struct vnt_private *priv, unsigned int idx);
> > static int device_tx_srv(struct vnt_private *priv, unsigned int idx);
> > static bool device_alloc_rx_buf(struct vnt_private *, struct vnt_rx_desc *);
> > +static void device_init_rx_desc(struct vnt_private *priv, struct vnt_rx_desc *rd);
> > static void device_free_rx_buf(struct vnt_private *priv,
> > struct vnt_rx_desc *rd);
> > static void device_init_registers(struct vnt_private *priv);
> > @@ -615,6 +616,8 @@ static int device_init_rd0_ring(struct vnt_private *priv)
> > dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
> > ret = -ENOMEM;
> > goto err_free_rd;
> > + } else {
> > + device_init_rx_desc(priv, desc);
> > }
>
> None of these else statements make sense. It should be:
>
> ret = -ENOMEM;
> goto err_free_rd;
> }
>
> device_init_rx_desc(priv, desc);
> desc->next = &priv->aRD0Ring[(i + 1) % priv->opts.rx_descs0];
That does look better, will be changed.
> I haven't reviewed the patch totally. I don't understand why it's doing
> this here instead of at the end. But then I don't understand why it
> needs to be in a separate function at all.
>
> This patch does not make sense. The commit description says that this
> is a "preparation" patch. Maybe fold it in with patch 5? The rule is
> "one thing per patch" not "half a thing per patch".
I thought splitting it like this would make it easier to review. But if
these preparation patches are not welcomed, I will squash them and
resend.
Thank you for spending time reviewing the patches.
Best regards,
Nam
© 2016 - 2026 Red Hat, Inc.