All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qasim Ijaz <qasdev00@gmail.com>
To: Jonas Gorski <jonas.gorski@gmail.com>
Cc: nbd@nbd.name, lorenzo@kernel.org, ryder.lee@mediatek.com,
	shayne.chen@mediatek.com, sean.wang@mediatek.com,
	matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
	chui-hao.chiu@mediatek.com, Bo.Jiao@mediatek.com,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH] wifi: mt76: mt7996: prevent uninit return in mt7996_mac_sta_add_links
Date: Sat, 22 Mar 2025 22:51:22 +0000	[thread overview]
Message-ID: <Z98-6kXoYdSaFtVR@qasdev.system> (raw)
In-Reply-To: <CAOiHx==UCeMQpywQJCLPQqipEW0tK9youRxdR5+_T1LuGp_EHA@mail.gmail.com>

On Sat, Mar 22, 2025 at 12:51:57PM +0100, Jonas Gorski wrote:
> Hi,
> 
> On Thu, Mar 20, 2025 at 9:19 PM Qasim Ijaz <qasdev00@gmail.com> wrote:
> >
> > If link_conf_dereference_protected() or mt7996_vif_link()
> > or link_sta_dereference_protected() fail the code jumps to
> > the error_unlink label and returns ret which is uninitialised.
> >
> > Fix this by setting err before jumping to error_unlink.
> >
> > Fixes: c7e4fc362443 ("wifi: mt76: mt7996: Update mt7996_mcu_add_sta to MLO support")
> > Fixes: dd82a9e02c05 ("wifi: mt76: mt7996: Rely on mt7996_sta_link in sta_add/sta_remove callbacks")
> > Signed-off-by: Qasim Ijaz <qasdev00@gmail.com>
> > ---
> >  drivers/net/wireless/mediatek/mt76/mt7996/main.c | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
> > index 91c64e3a0860..78f7f1fc867e 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
> > @@ -998,16 +998,22 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
> >                         continue;
> >
> >                 link_conf = link_conf_dereference_protected(vif, link_id);
> > -               if (!link_conf)
> > +               if (!link_conf) {
> > +                       err = -EINVAL;
> >                         goto error_unlink;
> > +               }
> >
> >                 link = mt7996_vif_link(dev, vif, link_id);
> > -               if (!link)
> > +               if (!link) {
> > +                       err = -EINVAL;
> >                         goto error_unlink;
> > +               }
> >
> >                 link_sta = link_sta_dereference_protected(sta, link_id);
> > -               if (!link_sta)
> > +               if (!link_sta) {
> > +                       err = -EINVAL
> 
> You are missing a semicolon at the end of the line.
> 

Good spot! not sure how that happened but I will resend a v2 patch.

> To also do some bike shedding, you could initialize err (with 0 or
> -EINVAL), and then change the err return to return err ? : -EINVAL;.
> But your way has an explicit error code assigned to each failure, even
> if it is always the same. So I won't claim my suggestion is better.
> 

Thanks for the suggestion, I think this could work however I think my 
current approach is more a bit more readable, so I will leave it as is.

Thanks,
Qasim

> Best regards,
> Jonas


      reply	other threads:[~2025-03-22 22:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 20:19 [PATCH] wifi: mt76: mt7996: prevent uninit return in mt7996_mac_sta_add_links Qasim Ijaz
2025-03-21 16:36 ` Dan Carpenter
2025-03-21 17:14   ` Lorenzo Bianconi
2025-03-21 17:35     ` Dan Carpenter
2025-03-22 10:01 ` Markus Elfring
2025-03-22 10:19   ` Dan Carpenter
2025-03-22 10:20   ` Johannes Berg
2025-03-22 10:43     ` Markus Elfring
2025-03-22 11:44 ` [PATCH] " Markus Elfring
2025-03-22 11:51 ` Jonas Gorski
2025-03-22 22:51   ` Qasim Ijaz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z98-6kXoYdSaFtVR@qasdev.system \
    --to=qasdev00@gmail.com \
    --cc=Bo.Jiao@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chui-hao.chiu@mediatek.com \
    --cc=jonas.gorski@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@nbd.name \
    --cc=ryder.lee@mediatek.com \
    --cc=sean.wang@mediatek.com \
    --cc=shayne.chen@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.