All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	linux-kernel@vger.kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	akpm@linux-foundation.org
Subject: Re: Buggy __free(kfree) usage pattern already in tree
Date: Fri, 15 Sep 2023 23:08:51 +0200	[thread overview]
Message-ID: <20230915210851.GA23174@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CAHk-=wicfvWPuRVDG5R1mZSxD8Xg=-0nLOiHay2T_UJ0yDX42g@mail.gmail.com>

On Fri, Sep 15, 2023 at 01:40:25PM -0700, Linus Torvalds wrote:

> Not because I think it's necessarily any kind of final rule, but
> because I think our whole cleanup thing is new enough that I think
> we're better off being a bit inflexible, and having a syntax where a
> simple "grep" ends up showing pretty much exactly what is going on wrt
> the pairing.

So in the perf-event conversion patches I do have this: 

	struct task_struct *task __free(put_task) = NULL;

	...

	if (pid != -1) {
		task = find_lively_task_by_vpid(pid);
		if (!task)
			return -ESRCH;
	}

	...

pattern. The having of task is fully optional in the code-flow.

I suppose I can try and rewrite that a little something like:

	...

	struct task_struct *task __free(put_task) =
		find_lively_task_by_vpid(pid); /* ensure pid==-1 returns NULL */

	if (!task && pid > 0)
		return -ESRCH;

	...


But a little later in that same function I then have:

	do {
		struct rw_semaphore *exec_update_lock __free(up_read) = NULL;
		if (task) {
			err = down_read_interruptible(&task->signal->exec_update_lock);
			if (err)
				return err;

			exec_update_lock = &task->signal->exec_update_lock;

			if (!perf_check_permissions(&attr, task))
				return -EACCESS;
		}

		... stuff serialized against exec *if* this is a task event ...

	} while (0);


And that might be a little harder to 'fix'.


I suppose I'm saying that when thing truly are conditional, this is a
useful pattern, but avoid where reasonably possible.

  reply	other threads:[~2023-09-15 21:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15  9:56 Buggy __free(kfree) usage pattern already in tree Alexey Dobriyan
2023-09-15 10:09 ` Bartosz Golaszewski
2023-09-15 17:04 ` Linus Torvalds
2023-09-15 17:22   ` Bartosz Golaszewski
2023-09-15 19:06     ` Linus Torvalds
2023-09-15 19:27       ` Bartosz Golaszewski
2023-09-15 20:03         ` Bartosz Golaszewski
2023-09-15 20:40           ` Linus Torvalds
2023-09-15 21:08             ` Peter Zijlstra [this message]
2023-09-15 21:18               ` Peter Zijlstra
2023-09-15 21:25                 ` Linus Torvalds
2023-09-15 21:22               ` Linus Torvalds
2023-09-15 21:32                 ` Peter Zijlstra
2023-09-15 21:50                   ` Linus Torvalds
2023-09-15 22:10                     ` Linus Torvalds
2023-09-15 22:13                     ` Peter Zijlstra
2023-09-19 12:57                       ` Peter Zijlstra
2023-09-19 12:59                         ` Peter Zijlstra
2023-09-19 13:10                           ` Peter Zijlstra
2023-09-19 19:35                             ` Peter Zijlstra
2023-09-20 11:02                               ` David Laight

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=20230915210851.GA23174@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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 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.