linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Felix Fietkau <nbd@nbd.name>,
	Johannes Berg <johannes@sipsolutions.net>,
	linux-wireless@vger.kernel.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [bug report] mt76: implement functions to get the response skb for MCU calls
Date: Fri, 14 Oct 2022 10:30:05 +0300	[thread overview]
Message-ID: <Y0kP/WOjnCexAPCy@kadam> (raw)
In-Reply-To: <Y0g8Ev4hE7m/kP3H@lore-desk>

On Thu, Oct 13, 2022 at 06:25:54PM +0200, Lorenzo Bianconi wrote:
> > I would like to revisit this question.  Last time I complained about
> > this Johannes responded but he misread what mt76_mcu_send_and_get_msg()
> > does.  I have looked at it as well and I also cannot explain what is
> > going on in that function.
> > 
> > I have looked at the callers and my first instinct is that maybe this
> > is dead stub code?  But then when I look at mt76x02u_mcu_send_msg() I
> > think "No, this is not stub code.  This should be returning the newly
> > allocated skb to the caller."
> > 
> > But then I think, surely at some point someone tested this code???  It
> > must be stub code.
> > 
> > Could we get some clarity on this?
> 
> for mt76x2 and mt76x0 we do not care of ret_skb (in fact we do not run
> mt76_mcu_send_and_get_msg() directly but we rely on mt76_mcu_send_msg()).
> For mt7921 we set mcu_skb_send_msg function pointer and not mcu_send_msg.

Ah thanks...  It's easy enough to silence the warning in Smatch but I
was never sure if it wasn't a bug.

> Moreover mt7921_mcu_get_eeprom() has been remove a while back.
> Am I missing something?

There are 12 callers for mt76_mcu_send_and_get_msg() and 11 of them
assume that the "ret_skb" is initialized (i.e. they assume that
the ->mcu_send_msg op is not used) so I get 11 Smatch warnings from
this...

Why not just do something like below?  It moves the ->mcu_send_msg()
call to the only place where it won't cause a crash.

regards,
dan carpenter

diff --git a/drivers/net/wireless/mediatek/mt76/mcu.c b/drivers/net/wireless/mediatek/mt76/mcu.c
index a8cafa39a56d..6bf0b7d8daee 100644
--- a/drivers/net/wireless/mediatek/mt76/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mcu.c
@@ -58,9 +58,6 @@ int mt76_mcu_send_and_get_msg(struct mt76_dev *dev, int cmd, const void *data,
 {
 	struct sk_buff *skb;
 
-	if (dev->mcu_ops->mcu_send_msg)
-		return dev->mcu_ops->mcu_send_msg(dev, cmd, data, len, wait_resp);
-
 	skb = mt76_mcu_msg_alloc(dev, data, len);
 	if (!skb)
 		return -ENOMEM;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 87db9498dea4..99f931c08da9 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -1383,6 +1383,9 @@ static inline int
 mt76_mcu_send_msg(struct mt76_dev *dev, int cmd, const void *data, int len,
 		  bool wait_resp)
 {
+	if (dev->mcu_ops->mcu_send_msg)
+		return dev->mcu_ops->mcu_send_msg(dev, cmd, data, len, wait_resp);
+
 	return mt76_mcu_send_and_get_msg(dev, cmd, data, len, wait_resp, NULL);
 }
 




  reply	other threads:[~2022-10-14  7:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-08 13:00 [bug report] mt76: implement functions to get the response skb for MCU calls Dan Carpenter
2021-10-08 14:03 ` Johannes Berg
2021-10-08 14:27   ` Dan Carpenter
2021-10-08 14:35     ` Dan Carpenter
2022-10-13 13:04     ` Dan Carpenter
2022-10-13 16:25       ` Lorenzo Bianconi
2022-10-14  7:30         ` Dan Carpenter [this message]
2022-10-14  8:11           ` Lorenzo Bianconi

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=Y0kP/WOjnCexAPCy@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=nbd@nbd.name \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).