public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Lachlan Hodges <lachlan.hodges@morsemicro.com>,
	Dan Callaghan <dan.callaghan@morsemicro.com>,
	Arien Judge <arien.judge@morsemicro.com>
Cc: ayman.grais@morsemicro.com, linux-wireless@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH wireless-next 02/35] wifi: mm81x: add command.c
Date: Fri, 06 Mar 2026 09:38:53 +0100	[thread overview]
Message-ID: <2e7f8bc64e13743deb4bf90eac2a50920af9f862.camel@sipsolutions.net> (raw)
In-Reply-To: <20260227041108.66508-3-lachlan.hodges@morsemicro.com> (sfid-20260227_051156_408438_F971C92F)

Hi,

Hm. So I _was_ going to say this just _looked_ bad, but now I think it's
actually wrong:

On Fri, 2026-02-27 at 15:10 +1100, Lachlan Hodges wrote:
> +int mm81x_cmd_sta_state(struct mm81x *mm, struct mm81x_vif *mm_vif, u16 aid,
> +			struct ieee80211_sta *sta,
> +			enum ieee80211_sta_state state)
> +{
> +	struct host_cmd_req_set_sta_state req;
> +	struct host_cmd_resp_set_sta_state resp;
> +
> +	memset(&req, 0, sizeof(req));

This is fine of course.

> +	mm81x_cmd_init(mm, &req.hdr, HOST_CMD_ID_SET_STA_STATE, mm_vif->id,
> +		       sizeof(req));
> +
> +	memcpy(req.sta_addr, sta->addr, sizeof(req.sta_addr));
> +	req.aid = cpu_to_le16(aid);
> +	req.state = cpu_to_le16(state);
> +	req.uapsd_queues = sta->uapsd_queues;

(you write other fields here otherwise it'd be useless)


But then there are cases like this:

> +int mm81x_cmd_add_if(struct mm81x *mm, u16 *vif_id, const u8 *addr,
> +		     enum nl80211_iftype type)
> +{
> +	int ret;
> +	struct host_cmd_req_add_interface req;
> +	struct host_cmd_resp_add_interface resp;
> +
> +	mm81x_cmd_init(mm, &req.hdr, HOST_CMD_ID_ADD_INTERFACE, 0, sizeof(req));
> +
> +	switch (type) {
> +	case NL80211_IFTYPE_STATION:
> +		req.interface_type = cpu_to_le32(HOST_CMD_INTERFACE_TYPE_STA);
> +		break;
> +	case NL80211_IFTYPE_AP:
> +		req.interface_type = cpu_to_le32(HOST_CMD_INTERFACE_TYPE_AP);
> +		break;
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +
> +	memcpy(req.addr.octet, addr, sizeof(req.addr.octet));
> +
> +	ret = mm81x_cmd_tx(mm, (struct host_cmd_resp *)&resp,
> +			   (struct host_cmd_req *)&req, sizeof(resp), 0);


Where you're sending uninitialised data to the firmware, regardless of
what the actual command does, mm81x_cmd_init() doesn't initialise the
'pad' field in the header, and there might be per-command fields too?


It'd also be far more obvious that it's not sending uninitialised data
if it was simply each command built as a C99 initialiser:

#define INIT_HDR(_var, _cmd, _vif_id)                           \
        {                                                       \
                .message_id = cpu_to_le16(_cmd),                \
                .vif_id = cpu_to_le16(_vif_id),                 \
                .len = sizeof(_var) - sizeof(_var).hdr,         \
        }

...

int mm81x_cmd_sta_state(struct mm81x *mm, struct mm81x_vif *mm_vif, u16 aid,
                        struct ieee80211_sta *sta,
                        enum ieee80211_sta_state state)
{
        struct host_cmd_req_set_sta_state req = {
                .hdr = INIT_HDR(req, HOST_CMD_ID_SET_STA_STATE, mm_vif->id),
                .aid = cpu_to_le16(aid),
                .state = cpu_to_le16(state),
                .uapsd_queues = sta->uapsd_queues,
        };
        struct host_cmd_resp_set_sta_state resp;

        memcpy(req.sta_addr, sta->addr, sizeof(req.sta_addr));

        return mm81x_cmd_tx(mm, (struct host_cmd_resp *)&resp,
                            (struct host_cmd_req *)&req, sizeof(resp), 0);
}


etc.

That assumes .hdr is always the header, but that didn't seem
unreasonable. It also doesn't work for a few cases that dynamically
allocate (filter), but that could just use kzalloc() instead.


It also seems (and that's really nitpicking now) that the response
argument to mm81x_cmd_tx() is actually optional, so a few (more) places
like this one could use NULL there (e.g. also key removal, beacon timer,
frag threshold)

johannes

  reply	other threads:[~2026-03-06  8:38 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27  4:10 [PATCH wireless-next 00/35] wifi: mm81x: add mm81x driver Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 01/35] wifi: mm81x: add bus.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 02/35] wifi: mm81x: add command.c Lachlan Hodges
2026-03-06  8:38   ` Johannes Berg [this message]
2026-02-27  4:10 ` [PATCH wireless-next 03/35] wifi: mm81x: add command_defs.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 04/35] wifi: mm81x: add command.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 05/35] wifi: mm81x: add core.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 06/35] wifi: mm81x: add core.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 07/35] wifi: mm81x: add debug.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 08/35] wifi: mm81x: add debug.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 09/35] wifi: mm81x: add fw.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 10/35] wifi: mm81x: add fw.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 11/35] wifi: mm81x: add hif.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 12/35] wifi: mm81x: add hw.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 13/35] wifi: mm81x: add hw.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 14/35] wifi: mm81x: add mac.c Lachlan Hodges
2026-03-06  9:04   ` Johannes Berg
2026-03-09  4:43     ` Lachlan Hodges
2026-03-09  7:08       ` Johannes Berg
2026-03-09  9:23         ` Lachlan Hodges
2026-03-09  9:37           ` Johannes Berg
2026-03-20  6:39             ` Lachlan Hodges
2026-03-20  7:18               ` Johannes Berg
2026-03-20 10:06                 ` Arien Judge
2026-02-27  4:10 ` [PATCH wireless-next 15/35] wifi: mm81x: add mac.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 16/35] wifi: mm81x: add mmrc.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 17/35] wifi: mm81x: add mmrc.h Lachlan Hodges
2026-03-06  9:07   ` Johannes Berg
2026-02-27  4:10 ` [PATCH wireless-next 18/35] wifi: mm81x: add ps.c Lachlan Hodges
2026-03-06  9:07   ` Johannes Berg
2026-02-27  4:10 ` [PATCH wireless-next 19/35] wifi: mm81x: add ps.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 20/35] wifi: mm81x: add rate_code.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 21/35] wifi: mm81x: add rc.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 22/35] wifi: mm81x: add rc.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 23/35] wifi: mm81x: add sdio.c Lachlan Hodges
2026-02-27 11:10   ` Krzysztof Kozlowski
2026-03-02  6:30     ` Lachlan Hodges
2026-03-06  8:20       ` Johannes Berg
2026-02-27  4:10 ` [PATCH wireless-next 24/35] wifi: mm81x: add skbq.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 25/35] wifi: mm81x: add skbq.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 26/35] wifi: mm81x: add usb.c Lachlan Hodges
2026-03-06  9:11   ` Johannes Berg
2026-02-27  4:10 ` [PATCH wireless-next 27/35] wifi: mm81x: add yaps.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 28/35] wifi: mm81x: add yaps.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 29/35] wifi: mm81x: add yaps_hw.c Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 30/35] wifi: mm81x: add yaps_hw.h Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 31/35] dt-bindings: vendor-prefixes: add Morse Micro Lachlan Hodges
2026-02-27 10:50   ` Krzysztof Kozlowski
2026-02-27  4:10 ` [PATCH wireless-next 32/35] dt-bindings: net: wireless: morsemicro: add mm81x family Lachlan Hodges
2026-02-27 10:59   ` Krzysztof Kozlowski
2026-02-27  4:10 ` [PATCH wireless-next 33/35] mmc: sdio: add Morse Micro vendor ids Lachlan Hodges
2026-02-27 10:49   ` Krzysztof Kozlowski
2026-03-04 16:45   ` Ulf Hansson
2026-02-27  4:10 ` [PATCH wireless-next 34/35] wifi: mm81x: add Kconfig and Makefile Lachlan Hodges
2026-02-27  4:10 ` [PATCH wireless-next 35/35] wifi: mm81x: add MAINTAINERS entry Lachlan Hodges

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=2e7f8bc64e13743deb4bf90eac2a50920af9f862.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=arien.judge@morsemicro.com \
    --cc=ayman.grais@morsemicro.com \
    --cc=dan.callaghan@morsemicro.com \
    --cc=lachlan.hodges@morsemicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    /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