Re: [PATCH net-next v4 5/8] mfd: zl3073x: Add functions to work with register mailboxes
From: Andrew Lunn
Date: Thu Apr 24 2025 - 12:44:12 EST
> +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