From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C07D3B3888 for ; Wed, 15 Jul 2026 16:27:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784132859; cv=none; b=FZp0b1vyJufQpB5Ws+bg8R3+8jqkDJhTHYmq++vY7hthMQ+r/zrNLzlaeUR14rOTeovEZu3ptYrWLKkRSYzZqJe3jHH0oIz7VkeNooLnYEYvRai8cQk/ndHca5u1BW2AqzQlTixUQV+DadNmZlS4JgzEL5WaBCuGwmR9skHel5s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784132859; c=relaxed/simple; bh=E3nJlSCsUf+kk/ii0qBTn4eMnjIAujNl/rWYcGtGbrI=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=e552gkl8140cvODy/4961zeOvkUPAFtkUyvr2tMVuPHZ2Soq+ggnw8c1NvbwgBPaSG0gADzqq3rAp3hgNaJSJPmMugP4ZGbkD2fGSgC4NZQ2AOcrINYk/kMpiSwoy9z1WppGJG5IscQTB0LbR1N1uRoTOe8Rs9M8/VMeE15prSE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gsPU5j4F; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gsPU5j4F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68E0C1F00A3A; Wed, 15 Jul 2026 16:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784132855; bh=1mX/k/zihBqQMdFFT8EJ1j/yWXjBQ5pfPp4e9JHAGTU=; h=Date:From:Subject:To:Cc:References:In-Reply-To; b=gsPU5j4FdOQv0kZOsswaIQIBzfjCIWNJACfqtgQaqeZFAR6ws/rsVU5EvxPqFaNhO xjEtBCKsrOjVuXuyu7d3tCOrIdIIlRg9gfBNKwOMOxDbZKmNmi5+/IoaD/2Vlv14bN sXOqaZsfmypQm0Hdsv2J2kgrRE0p8q0MqO/eQpNpd36pT2RnmhwD/v89Lo/+sw9GnR MUg698ieesbwfDumI6TfrHKqr0HTGaV1V25HMUWsWWTsoM7tWUSyGpvU1W+oXQebpu /TWs8TKvw45TLKMjErODT9xiqeddmWkXrhEOoeUVDeoRMaiJVMS/BZdQNtK49i8/gS C1ykyScvHX9WA== Message-ID: Date: Wed, 15 Jul 2026 18:27:31 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Vincent Mailhol Subject: Re: [PATCH 2/3] container_of: remove useless pair of parentheses To: Greg Kroah-Hartman Cc: Alexey Dobriyan , Andrew Morton , Rasmus Villemoes , Sakari Ailus , Nick Desaulniers , Alexander Lobakin , Arnd Bergmann , David Sterba , Ivo van Doorn , linux-kernel@vger.kernel.org References: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> <20260714-containerof_refactor-v1-2-b5c31164d2ad@kernel.org> <2026071505-fracture-opt-5374@gregkh> Content-Language: en-US Autocrypt: addr=mailhol@kernel.org; keydata= xjMEZluomRYJKwYBBAHaRw8BAQdAf+/PnQvy9LCWNSJLbhc+AOUsR2cNVonvxhDk/KcW7FvN JFZpbmNlbnQgTWFpbGhvbCA8bWFpbGhvbEBrZXJuZWwub3JnPsKZBBMWCgBBFiEE7Y9wBXTm fyDldOjiq1/riG27mcIFAmdfB/kCGwMFCQp/CJcFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcC F4AACgkQq1/riG27mcKBHgEAygbvORJOfMHGlq5lQhZkDnaUXbpZhxirxkAHwTypHr4A/joI 2wLjgTCm5I2Z3zB8hqJu+OeFPXZFWGTuk0e2wT4JzjgEZx4y8xIKKwYBBAGXVQEFAQEHQJrb YZzu0JG5w8gxE6EtQe6LmxKMqP6EyR33sA+BR9pLAwEIB8J+BBgWCgAmFiEE7Y9wBXTmfyDl dOjiq1/riG27mcIFAmceMvMCGwwFCQPCZwAACgkQq1/riG27mcJU7QEA+LmpFhfQ1aij/L8V zsZwr/S44HCzcz5+jkxnVVQ5LZ4BANOCpYEY+CYrld5XZvM8h2EntNnzxHHuhjfDOQ3MAkEK In-Reply-To: <2026071505-fracture-opt-5374@gregkh> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15/07/2026 at 16:57, Greg Kroah-Hartman wrote: > On Wed, Jul 15, 2026 at 04:51:28PM +0200, Vincent Mailhol wrote: >> On 15/07/2026 at 16:30, Alexey Dobriyan wrote: >>> On Tue, Jul 14, 2026 at 08:18:02PM +0200, Vincent Mailhol wrote: >>>> The last expression in container_of() doesn't need an extra pair of >>>> parenthesis. Remove it. >>>> >>>> Signed-off-by: Vincent Mailhol >>>> --- >>>> include/linux/container_of.h | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/include/linux/container_of.h b/include/linux/container_of.h >>>> index 28500a62ab7e..68153170db32 100644 >>>> --- a/include/linux/container_of.h >>>> +++ b/include/linux/container_of.h >>>> @@ -21,7 +21,7 @@ >>>> static_assert(__same_type(*(ptr), typeof_member(type, member)) || \ >>>> __same_type(*(ptr), void), \ >>>> "pointer type mismatch in container_of()"); \ >>>> - ((type *)(__mptr - offsetof(type, member))); }) >>>> + (type *)(__mptr - offsetof(type, member)); }) >>> >>> container_of_const() has the same problem. >> >> Yes. But scoped I my series to the container_of() macro only. >> >> I don't plan to send a follow-up patch to remove the other useless >> parenthesis. The things which really bothered me was the __mptr >> variable which I removed in patch #3. And with that, I am done with >> what I wanted to contribute in this file. >> >> But you are welcome to do this clean-up if you feel the need for it. >> >>> And it should parenthesize first argument to _Generic. >> >> Do you mean like this: >> >> #define container_of_const(ptr, type, member) \ >> _Generic((ptr), \ >> const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\ >> default: ((type *)container_of(ptr, type, member)) \ >> ) >> >> ? >> >> Why would parenthesis be needed here? I don't see what kind of >> expression would make the current implementation unsafe. > > It took me a while working with container_of_const() to get it right > with the (), so be careful removing any. I just tested this patch: ---8<--- diff --git a/include/linux/container_of.h b/include/linux/container_of.h index 1f6ebf27d962..03d5b91534a7 100644 --- a/include/linux/container_of.h +++ b/include/linux/container_of.h @@ -34,8 +34,8 @@ */ #define container_of_const(ptr, type, member) \ _Generic(ptr, \ - const typeof(*(ptr)) *: ((const type *)container_of(ptr, type, member)),\ - default: ((type *)container_of(ptr, type, member)) \ + const typeof(*(ptr)) *: (const type *)container_of(ptr, type, member),\ + default: (type *)container_of(ptr, type, member) \ ) #endif /* _LINUX_CONTAINER_OF_H */ ---8<--- I could compile and boot it, no problem (I am actually writing this message from a machine on which this patch is applied). So, yes, I believe that these two pairs of parenthesis can be removed. Just not sure if it is worth it. For container_of(), the parenthesis removal was part of a series with more meaningful changes. I don't feel exited of sending another series to just remove the container_of_const() parenthesis. Yours sincerely, Vincent Mailhol