From: Greg KH <gregkh@linuxfoundation.org>
To: Venkata Swamy Kassa <venkatswamy7@gmail.com>
Cc: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, Kees Cook <kees@kernel.org>,
Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH 1/2] kcsan: test: Adjust "expect" allocation type for kmalloc_obj
Date: Fri, 27 Feb 2026 15:27:17 -0500 [thread overview]
Message-ID: <2026022703-knoll-duckling-0285@gregkh> (raw)
In-Reply-To: <20260227185021.767948-2-venkata.swamy.kassa@hexagon.com>
On Fri, Feb 27, 2026 at 06:50:20PM +0000, Venkata Swamy Kassa wrote:
> From: Kees Cook <kees@kernel.org>
>
> The call to kmalloc_obj(observed.lines) returns "char (*)[3][512]",
> a pointer to the whole 2D array. But "expect" wants to be "char (*)[512]",
> the decayed pointer type, as if it were observed.lines itself (though
> without the "3" bounds). This produces the following build error:
>
> ../kernel/kcsan/kcsan_test.c: In function '__report_matches':
> ../kernel/kcsan/kcsan_test.c:171:16: error: assignment to 'char (*)[512]' from incompatible pointer type 'char (*)[3][512]'
> [-Wincompatible-pointer-types]
> 171 | expect = kmalloc_obj(observed.lines);
> | ^
>
> Instead of changing the "expect" type to "char (*)[3][512]" and
> requiring a dereference at each use (e.g. "(expect*)[0]"), just
> explicitly cast the return to the desired type.
>
> Note that I'm intentionally not switching back to byte-based "kmalloc"
> here because I cannot find a way for the Coccinelle script (which will
> be used going forward to catch future conversions) to exclude this case.
>
> Tested with:
>
> $ ./tools/testing/kunit/kunit.py run \
> --kconfig_add CONFIG_DEBUG_KERNEL=y \
> --kconfig_add CONFIG_KCSAN=y \
> --kconfig_add CONFIG_KCSAN_KUNIT_TEST=y \
> --arch=x86_64 --qemu_args '-smp 2' kcsan
>
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
> kernel/kcsan/kcsan_test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/kcsan/kcsan_test.c b/kernel/kcsan/kcsan_test.c
> index 79e655ea4ca1..ae758150ccb9 100644
> --- a/kernel/kcsan/kcsan_test.c
> +++ b/kernel/kcsan/kcsan_test.c
> @@ -168,7 +168,7 @@ static bool __report_matches(const struct expect_report *r)
> if (!report_available())
> return false;
>
> - expect = kmalloc_obj(observed.lines);
> + expect = (typeof(expect))kmalloc_obj(observed.lines);
> if (WARN_ON(!expect))
> return false;
>
> --
> 2.43.0
>
>
Why was this part of a usb patch series?
thanks,
greg k-h
next prev parent reply other threads:[~2026-02-27 20:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 18:50 [PATCH 0/2] usb: typec: hd3ss3220: Add sysfs interface for role state Venkata Swamy Kassa
2026-02-27 18:50 ` [PATCH 1/2] kcsan: test: Adjust "expect" allocation type for kmalloc_obj Venkata Swamy Kassa
2026-02-27 20:27 ` Greg KH [this message]
2026-02-27 18:50 ` [PATCH 2/2] usb-typec-hd3ss3220-Add-sysfs-attribute-for-USB-role Venkata Swamy Kassa
2026-02-27 20:26 ` Greg KH
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=2026022703-knoll-duckling-0285@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=venkatswamy7@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox