2022-06-22 15:54:39

by Felix Schlepper

[permalink] [raw]
Subject: [PATCH v3 3/3] Staging: rtl8192e: Cleaning up error handling

This error handling is more readable and reduces code size.

Signed-off-by: Felix Schlepper <[email protected]>
---
drivers/staging/rtl8192e/rtllib_tx.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_tx.c b/drivers/staging/rtl8192e/rtllib_tx.c
index 1307cf55741a..b246f5e0cad7 100644
--- a/drivers/staging/rtl8192e/rtllib_tx.c
+++ b/drivers/staging/rtl8192e/rtllib_tx.c
@@ -214,19 +214,18 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,

for (i = 0; i < nr_frags; i++) {
txb->fragments[i] = dev_alloc_skb(txb_size);
- if (unlikely(!txb->fragments[i])) {
- i--;
- break;
- }
+ if (unlikely(!txb->fragments[i]))
+ goto err_free;
memset(txb->fragments[i]->cb, 0, sizeof(txb->fragments[i]->cb));
}
- if (unlikely(i != nr_frags)) {
- while (i >= 0)
- dev_kfree_skb_any(txb->fragments[i--]);
- kfree(txb);
- return NULL;
- }
+
return txb;
+
+err_free:
+ while (--i >= 0)
+ dev_kfree_skb_any(txb->fragments[i]);
+
+ return NULL;
}

static int rtllib_classify(struct sk_buff *skb, u8 bIsAmsdu)
--
2.36.1


2022-06-23 07:03:02

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH v3 3/3] Staging: rtl8192e: Cleaning up error handling

On Wed, Jun 22, 2022 at 05:12:46PM +0200, Felix Schlepper wrote:
> This error handling is more readable and reduces code size.

There isn't a reduction in code size.

>
> Signed-off-by: Felix Schlepper <[email protected]>
> ---
> drivers/staging/rtl8192e/rtllib_tx.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/staging/rtl8192e/rtllib_tx.c b/drivers/staging/rtl8192e/rtllib_tx.c
> index 1307cf55741a..b246f5e0cad7 100644
> --- a/drivers/staging/rtl8192e/rtllib_tx.c
> +++ b/drivers/staging/rtl8192e/rtllib_tx.c
> @@ -214,19 +214,18 @@ static struct rtllib_txb *rtllib_alloc_txb(int nr_frags, int txb_size,
>
> for (i = 0; i < nr_frags; i++) {
> txb->fragments[i] = dev_alloc_skb(txb_size);
> - if (unlikely(!txb->fragments[i])) {
> - i--;
> - break;
> - }
> + if (unlikely(!txb->fragments[i]))
> + goto err_free;
> memset(txb->fragments[i]->cb, 0, sizeof(txb->fragments[i]->cb));
> }
> - if (unlikely(i != nr_frags)) {
> - while (i >= 0)
> - dev_kfree_skb_any(txb->fragments[i--]);
> - kfree(txb);
> - return NULL;
> - }
> +
> return txb;
> +
> +err_free:
> + while (--i >= 0)
> + dev_kfree_skb_any(txb->fragments[i]);

There needs to be a kfree(txb);

regards,
dan carpenter


> +
> + return NULL;
> }
>