From: Jani Nikula <jani.nikula@linux.intel.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: Arnd Bergmann <arnd@kernel.org>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Badal Nilawar <badal.nilawar@intel.com>,
Ashutosh Dixit <ashutosh.dixit@intel.com>,
Arnd Bergmann <arnd@arndb.de>,
Matt Roper <matthew.d.roper@intel.com>,
Vinay Belgaumkar <vinay.belgaumkar@intel.com>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
Andi Shyti <andi.shyti@linux.intel.com>
Subject: Re: [PATCH] drm/i915/mtl: avoid stringop-overflow warning
Date: Wed, 25 Oct 2023 14:53:38 +0300 [thread overview]
Message-ID: <87o7gm9av1.fsf@intel.com> (raw)
In-Reply-To: <20231024174153.byeq7ctssvxuwa4z@zenone.zhora.eu>
On Tue, 24 Oct 2023, Andi Shyti <andi.shyti@kernel.org> wrote:
> Hi Jani,
>
>> > static void rc6_res_reg_init(struct intel_rc6 *rc6)
>> > {
>> > - memset(rc6->res_reg, INVALID_MMIO_REG.reg, sizeof(rc6->res_reg));
>>
>> That's just bollocks. memset() is byte granularity, while
>> INVALID_MMIO_REG.reg is u32. If the value was anything other than 0,
>> this would break.
>
> Actually it's:
>
> void *memset(void *s, int c, size_t count)
And? It still sets each byte in s to (the lowest 8 bits of) c.
>
>> And you're not supposed to look at the guts of i915_reg_t to begin with,
>> that's why it's a typedef. Basically any code that accesses the members
>> of i915_reg_t outside of its implementation are doing it wrong.
>>
>> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
>
> in any case, I agree with your argument, but why can't we simply
> do:
>
> memset(rc6->res_reg, 0, sizeof(rc6->res_reg));
>
> ?
We can simply do a lot of things in C, but IMO that's semantically
wrong. i915_reg_t is supposed to be an opaque type. We're not supposed
to know what it contains, and what values are valid or invalid for it.
That's one of the reasons we have i915_reg_t in the first place (type
safety being the primary one).
Basically you should be able to do
-#define INVALID_MMIO_REG _MMIO(0)
+#define INVALID_MMIO_REG _MMIO(0xdeadbeef)
and expect everything to still work.
BR,
Jani.
>
> The patch looks to me like it's being more complex that it
> should.
>
> Andi
--
Jani Nikula, Intel
next prev parent reply other threads:[~2023-10-25 11:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-16 20:10 [PATCH] drm/i915/mtl: avoid stringop-overflow warning Arnd Bergmann
2023-10-16 22:10 ` [Intel-gfx] " Andi Shyti
2023-10-17 5:27 ` Arnd Bergmann
2023-10-23 12:49 ` Jani Nikula
2023-10-24 17:41 ` Andi Shyti
2023-10-25 11:53 ` Jani Nikula [this message]
2023-10-26 12:18 ` [Intel-gfx] " Jani Nikula
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=87o7gm9av1.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=airlied@gmail.com \
--cc=andi.shyti@kernel.org \
--cc=andi.shyti@linux.intel.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=ashutosh.dixit@intel.com \
--cc=badal.nilawar@intel.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.d.roper@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=tvrtko.ursulin@linux.intel.com \
--cc=vinay.belgaumkar@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox