[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5094e051-5504-48a5-b411-ed1a0d949eeb@lunn.ch>
Date: Thu, 24 Apr 2025 18:43:32 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Ivan Vecera <ivecera@...hat.com>
Cc: netdev@...r.kernel.org, Vadim Fedorenko <vadim.fedorenko@...ux.dev>,
Arkadiusz Kubalewski <arkadiusz.kubalewski@...el.com>,
Jiri Pirko <jiri@...nulli.us>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Prathosh Satish <Prathosh.Satish@...rochip.com>,
Lee Jones <lee@...nel.org>, Kees Cook <kees@...nel.org>,
Andy Shevchenko <andy@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Michal Schmidt <mschmidt@...hat.com>, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH net-next v4 5/8] mfd: zl3073x: Add functions to work with
register mailboxes
> +static int
> +zl3073x_write_reg(struct zl3073x_dev *zldev, unsigned int reg, const void *val)
> +{
> + unsigned int len;
> + u8 buf[6];
> + int rc;
> +
> + /* Offset of the last item in the indexed register or offset of
> + * the non-indexed register itself.
> + */
> + if (ZL_REG_OFFSET(reg) > ZL_REG_MAX_OFFSET(reg)) {
> + dev_err(zldev->dev, "Index of out range for reg 0x%04lx\n",
> + ZL_REG_ADDR(reg));
> + return -EINVAL;
> + }
> +
> + len = ZL_REG_SIZE(reg);
I suggested you add helpers for zl3073x_write_reg_u8(),
zl3073x_write_reg_u16(), zl3073x_write_reg_32(), and
zl3073x_write_reg_48(). The compiler will then do type checking for
val, ensure what you pass is actually big enough.
Here you have a void *val. You have no idea how big a value that
pointer points to, and the compiler is not helping you.
I suggest you add the individual helpers. If you decided to keep the
register meta data, you can validate the correct helper has been
called.
Andrew
Powered by blists - more mailing lists