public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sultan Alsawaf <sultan@kerneltoast.com>
To: "Du, Bin" <bin.du@amd.com>
Cc: mchehab@kernel.org, hverkuil@xs4all.nl,
	laurent.pinchart+renesas@ideasonboard.com,
	bryan.odonoghue@linaro.org, sakari.ailus@linux.intel.com,
	prabhakar.mahadev-lad.rj@bp.renesas.com,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	pratap.nirujogi@amd.com, benjamin.chan@amd.com, king.li@amd.com,
	gjorgji.rosikopulos@amd.com, Phil.Jawich@amd.com,
	Dominic.Antony@amd.com, mario.limonciello@amd.com,
	richard.gong@amd.com, anson.tsao@amd.com,
	Alexey Zagorodnikov <xglooom@gmail.com>
Subject: Re: [PATCH v4 3/7] media: platform: amd: Add isp4 fw and hw interface
Date: Thu, 25 Sep 2025 00:20:12 -0700	[thread overview]
Message-ID: <aNTtLHDHf_ozenC-@sultan-box> (raw)
In-Reply-To: <2f6c190d-aed0-4a27-8b20-1a4833d7edf7@amd.com>

On Thu, Sep 25, 2025 at 11:56:13AM +0800, Du, Bin wrote:
> On 9/24/2025 3:09 PM, Sultan Alsawaf wrote:
> > On Tue, Sep 23, 2025 at 05:24:11PM +0800, Du, Bin wrote:
> > > On 9/22/2025 5:55 AM, Sultan Alsawaf wrote:
> > > > On Thu, Sep 11, 2025 at 06:08:43PM +0800, Bin Du wrote:
> > > > > +	struct isp4if_cmd_element *cmd_ele = NULL;
> > > > > +	struct isp4if_rb_config *rb_config;
> > > > > +	struct device *dev = ispif->dev;
> > > > > +	struct isp4fw_cmd cmd = {};
> > > > 
> > > > Use memset() to guarantee padding bits of cmd are zeroed, since this may not
> > > > guarantee it on all compilers.
> > > > 
> > > 
> > > Sure, will do it in the next version. Just a question, padding bits seem
> > > never to be used, will it cause any problem if they are not zeroed?
> > 
> > Padding bits, if there are any, are used by isp4if_compute_check_sum() and are
> > also sent to the firmware.
> > 
> 
> Yes, this will impact the checksum value. However, based on my
> understanding, it will not affect the error detection outcome, since the
> firmware uses the same padding bits during both checksum calculation and
> comparison. I apologize for the minor disagreement—I just want to avoid
> introducing redundant code, especially given that similar scenarios appear a
> lot. Originally, we used memset in the initial version, but switched to { }
> initialization in subsequent versions based on review feedback. Please feel
> free to share your ideas, if you believe it is still necessary, we will add
> them.

Ah, I see Sakari suggested that during a prior review [1].

Whenever a struct is sent outside of the kernel, padding bits should be zeroed
for a few reasons:

1. Uninitialized padding bits can expose sensitive information from kernel
   memory, which can be a security concern.

2. There is no guarantee that the recipient will always behave the same way with
   different values for the padding bits. In this case for example, I cannot
   look at the ISP source code and say for sure that the padding bits don't
   affect its operation. And even if I could, that may always change with a new
   firmware version.

3. You can ensure more reliable testing results by guaranteeing that the padding
   bits are the same value (zero) for everyone. For example, if the padding bits
   accidentally affected the firmware, some users with different padding bits
   values could experience bugs that you cannot reproduce in your lab or dev
   environment.

The only way to ensure padding bits are zeroed on all compilers is to use
memset; using { } won't do this on every compiler or every compiler version or
even every compiler optimization level [2].

So I still believe it is necessary to use memset for those structs which are
sent outside of the kernel, in this case for the structs sent to firmware. For
structs which are used _only inside_ the kernel, it is preferred to use { }.

[1] https://lore.kernel.org/all/aIclcwRep3F_z7PF@kekkonen.localdomain/
[2] https://interrupt.memfault.com/blog/c-struct-padding-initialization#strategy-4---gcc-extension

Sultan

  reply	other threads:[~2025-09-25  7:20 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 10:08 [PATCH v4 0/7] Add AMD ISP4 driver Bin Du
2025-09-11 10:08 ` [PATCH v4 1/7] media: platform: amd: Introduce amd isp4 capture driver Bin Du
2025-09-21 20:23   ` Sultan Alsawaf
2025-09-23  7:56     ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 2/7] media: platform: amd: low level support for isp4 firmware Bin Du
2025-09-21 20:31   ` Sultan Alsawaf
2025-09-23  8:05     ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 3/7] media: platform: amd: Add isp4 fw and hw interface Bin Du
2025-09-21 21:55   ` Sultan Alsawaf
2025-09-23  9:24     ` Du, Bin
2025-09-24  7:09       ` Sultan Alsawaf
2025-09-25  3:56         ` Du, Bin
2025-09-25  7:20           ` Sultan Alsawaf [this message]
2025-09-25  9:42             ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 4/7] media: platform: amd: isp4 subdev and firmware loading handling added Bin Du
2025-09-23  7:23   ` Sultan Alsawaf
2025-09-30  7:30     ` Du, Bin
2025-10-01  7:24       ` Sultan Alsawaf
2025-10-10 10:25         ` Du, Bin
2025-10-11  7:18           ` Sultan Alsawaf
2025-10-11  8:27             ` Du, Bin
2025-09-11 10:08 ` [PATCH v4 5/7] media: platform: amd: isp4 video node and buffers " Bin Du
2025-10-01  6:53   ` Sultan Alsawaf
2025-10-11  9:30     ` Du, Bin
2025-10-12  6:08       ` Sultan Alsawaf
2025-10-13  9:55         ` Du, Bin
2025-10-16  8:13       ` Du, Bin
2025-10-17  8:34         ` Sultan Alsawaf
2025-10-17  9:53           ` Du, Bin
2025-10-19 22:11             ` Sultan Alsawaf
2025-09-11 10:08 ` [PATCH v4 6/7] media: platform: amd: isp4 debug fs logging and more descriptive errors Bin Du
2025-09-11 10:08 ` [PATCH v4 7/7] Documentation: add documentation of AMD isp 4 driver Bin Du
2025-09-19  3:24 ` [PATCH v4 0/7] Add AMD ISP4 driver Du, Bin
2025-09-19 12:23   ` Laurent Pinchart
2025-09-22  2:50     ` Du, Bin

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=aNTtLHDHf_ozenC-@sultan-box \
    --to=sultan@kerneltoast.com \
    --cc=Dominic.Antony@amd.com \
    --cc=Phil.Jawich@amd.com \
    --cc=anson.tsao@amd.com \
    --cc=benjamin.chan@amd.com \
    --cc=bin.du@amd.com \
    --cc=bryan.odonoghue@linaro.org \
    --cc=gjorgji.rosikopulos@amd.com \
    --cc=hverkuil@xs4all.nl \
    --cc=king.li@amd.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mchehab@kernel.org \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=pratap.nirujogi@amd.com \
    --cc=richard.gong@amd.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=xglooom@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