lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260129142836.GF2223369@nvidia.com>
Date: Thu, 29 Jan 2026 10:28:36 -0400
From: Jason Gunthorpe <jgg@...dia.com>
To: Bartosz Golaszewski <brgl@...nel.org>
Cc: Laurent Pinchart <laurent.pinchart@...asonboard.com>,
	Johan Hovold <johan@...nel.org>,
	Bartosz Golaszewski <bartosz.golaszewski@....qualcomm.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Danilo Krummrich <dakr@...nel.org>,
	"Rafael J . Wysocki" <rafael@...nel.org>,
	Tzung-Bi Shih <tzungbi@...nel.org>,
	Linus Walleij <linusw@...nel.org>, Jonathan Corbet <corbet@....net>,
	Shuah Khan <shuah@...nel.org>,
	Wolfram Sang <wsa+renesas@...g-engineering.com>,
	Simona Vetter <simona.vetter@...ll.ch>,
	Dan Williams <dan.j.williams@...el.com>, linux-doc@...r.kernel.org,
	linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 0/3] Revert "revocable: Revocable resource management"

On Thu, Jan 29, 2026 at 08:50:30AM -0500, Bartosz Golaszewski wrote:

> and the ownership of that data belongs to the driver. There's no way we could
> address it now so the next best thing is to work towards moving the ownership

Think positive!

If this is common:

 struct my_i2c_drv_data *data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);

Then change it into

 struct my_i2c_drv_data *data = devm_i2c_adaptor_alloc(struct my_i2c_drv_data, adap);

With Coccinelle or sed.

Audit all the drivers to catch the stragglers.

Now you have a refcount. Look at how fwctl_alloc_device() works to
understand the pattern.

Kernel community has done far harder transformations than this :)

Sure it is 200 drivers, I would ask Coccinelle team for help.

Here is how I would approach it.

First, grep to find all the candidates:

$ git grep -E '^\s+struct i2c_adapter[^*]*;'

Get a kernel built with all those compiling and get a clangd database
going. Make a list of all possible candidate files with grep.

AI tells me (and AI is never right about Coccinelle sadly) that you
could use this:

// C1: Find any struct that has a member of type "struct i2c_adapter"
@ has_i2c_adapter_struct @
type S;
@@
struct S {
  ...
  struct i2c_adapter;
  ...
};

// C2: Replace sizeof(...) with fixme_sizeof(...)
@ sizeof_i2c_adapter_struct depends on has_i2c_adapter_struct @
type has_i2c_adapter_struct.S;
@@
- sizeof(struct S)
+ fixme_sizeof(struct S)

The idea being the only reason to do sizeof(S) is for an allocation
and we want to find every allocation of a wrapper struct to fix it.

Now you have an index of all lines that need touching.

Look for common patterns, use Coccinelle or sed to make bulk
replacements. Group patches of all similar transformations. Sweep
through with grep to clean anything not caught. Probably there will be
a couple drivers doing something utterly insane, meditate on them and
clean them up by hand (this is what clangd is helpful for)

Betcha you can get through it in a few hours!

Jason

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ