All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Alison Schofield <alison.schofield@intel.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>,
	Dave Jiang <dave.jiang@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <iweiny@kernel.org>, Dan Williams <djbw@kernel.org>,
	Li Ming <ming.li@zohomail.com>,
	linux-cxl@vger.kernel.org
Subject: Re: [PATCH v2 2/2] cxl/region: Use __free(put_device) in find_pos_and_ways()
Date: Wed, 22 Jul 2026 00:56:48 +0100	[thread overview]
Message-ID: <20260722005648.360ddf68@jic23-huawei> (raw)
In-Reply-To: <03aceaa0001651c28f221988c9e845f59bf1d84d.1784654628.git.alison.schofield@intel.com>

On Tue, 21 Jul 2026 10:37:04 -0700
Alison Schofield <alison.schofield@intel.com> wrote:

> Use __free(put_device) for the switch decoder reference returned by
> device_find_child() instead of releasing it with an open-coded
> put_device().
> 
> This matches the scoped device reference handling used elsewhere in
> the file.
> 
> Suggested-by: Li Ming <ming.li@zohomail.com>
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
> 
> This is a new patch added in series after the UAF fixup in patch 1/2.
> 
> 
>  drivers/cxl/core/region.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index c86dd9d55e93..4d7d96d03ece 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -1911,9 +1911,9 @@ static int match_switch_decoder_by_range(struct device *dev,
>  static int find_pos_and_ways(struct cxl_port *port, struct range *range,
>  			     int *pos, int *ways)
>  {
> +	struct device *dev __free(put_device) = NULL;

No to this.  See rules in cleanup.h.
This is the path to grumpy Linus if he happens to spot it.

Short story is declaration and destructor must be in same statement
as the constructor.  Here that means 

	struct device *dev __free(put_device) =
		device_find_child(&parent->dev, range, match_switch_decoder_by_range);

I would go long on that second line given it's only a bit beyond 80 chars
and the two lines are horrible enough to read without becoming 3.



>  	struct cxl_switch_decoder *cxlsd;
>  	struct cxl_port *parent;
> -	struct device *dev;
>  	int rc = -ENXIO;
>  
>  	parent = parent_port_of(port);
> @@ -1945,8 +1945,6 @@ static int find_pos_and_ways(struct cxl_port *port, struct range *range,
>  			dev_name(port->parent_dport->dport_dev),
>  			dev_name(&cxlsd->cxld.dev));
>  
> -	put_device(dev);
> -
>  	return rc;
>  }
>  


  reply	other threads:[~2026-07-21 23:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 17:37 [PATCH v2 1/2] cxl/region: Fix use-after-free in find_pos_and_ways() error path Alison Schofield
2026-07-21 17:37 ` [PATCH v2 2/2] cxl/region: Use __free(put_device) in find_pos_and_ways() Alison Schofield
2026-07-21 23:56   ` Jonathan Cameron [this message]
2026-07-24 21:57     ` Alison Schofield
2026-07-22  5:25   ` Li Ming
2026-07-21 17:50 ` [PATCH v2 1/2] cxl/region: Fix use-after-free in find_pos_and_ways() error path sashiko-bot
2026-07-24 21:40   ` Alison Schofield
2026-07-21 23:53 ` Jonathan Cameron
2026-07-24 21:54   ` Alison Schofield
2026-07-22  5:24 ` Li Ming

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=20260722005648.360ddf68@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=djbw@kernel.org \
    --cc=iweiny@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=ming.li@zohomail.com \
    --cc=vishal.l.verma@intel.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.