All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jaehee Park <jhpark1013@gmail.com>
Cc: "Jérôme Pouiller" <jerome.pouiller@silabs.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	outreachy@lists.linux.dev, "Stefano Brivio" <sbrivio@redhat.com>
Subject: Re: [PATCH v2] staging: wfx: use container_of() to get vif
Date: Fri, 8 Apr 2022 09:19:36 +0300	[thread overview]
Message-ID: <20220408061936.GP3293@kadam> (raw)
In-Reply-To: <20220408032349.GA2132476@jaehee-ThinkPad-X1-Extreme>

On Thu, Apr 07, 2022 at 11:23:49PM -0400, Jaehee Park wrote:
> diff --git a/drivers/staging/wfx/wfx.h b/drivers/staging/wfx/wfx.h
> index 6594cc647c2f..78f2a416fe4f 100644
> --- a/drivers/staging/wfx/wfx.h
> +++ b/drivers/staging/wfx/wfx.h
> @@ -25,6 +25,8 @@
>  #define USEC_PER_TXOP 32 /* see struct ieee80211_tx_queue_params */
>  #define USEC_PER_TU 1024
>  
> +#define wvif_to_vif(ptr)(container_of((void *)ptr, struct ieee80211_vif, drv_priv))
> +

Better to make this a function.

Stefano's comments are correct.  It would have saved space with the 80
limit to do a "struct ieee80211_vif *vif = wvif_to_vif();" at the start
of the function.  Also dereferencing the results of a function call
like this, "frob(foo)->bar", without checking makes me itch.  If it's
at the top of the function then that's kind of different.  I normally
assume that the functions in the declaration block cannot fail.  From
analysing static checker warnings, putting functions which can fail in
that the declaration block is risky.

It's always better to test things but this patch looks correct to me:

The add interface does:

	struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv
        ...
	wvif->vif = vif;

The remove interface does:
	wvif->vif = NULL;

Those are the only places where ->vif is set container_of() will always
work.

regards,
dan carpenter


  parent reply	other threads:[~2022-04-08  6:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08  3:23 [PATCH v2] staging: wfx: use container_of() to get vif Jaehee Park
2022-04-08  4:45 ` Greg Kroah-Hartman
2022-04-08  5:44   ` Stefano Brivio
2022-04-09 14:07     ` Jérôme Pouiller
2022-04-12  4:18       ` Jaehee Park
2022-04-08  5:43 ` Stefano Brivio
2022-04-08 22:07   ` Jaehee Park
2022-04-08  6:19 ` Dan Carpenter [this message]
2022-04-12  3:57   ` Jaehee Park

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=20220408061936.GP3293@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jerome.pouiller@silabs.com \
    --cc=jhpark1013@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=outreachy@lists.linux.dev \
    --cc=sbrivio@redhat.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.