Re: [PATCH v2 2/7] USB: serial: xr: use a table for device-specific settings

From: Johan Hovold
Date: Tue Mar 30 2021 - 10:45:11 EST


On Wed, Mar 24, 2021 at 08:41:06AM +0100, Mauro Carvalho Chehab wrote:
> The same driver is used by a wide range of MaxLinear devices.
>
> Other models are close enough to use the same driver, but they
> use a different register set.
>
> So, instead of having the registers hardcoded at the driver,
> use a table. This will allow further patches to add support for
> other devices.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx>
> ---
> drivers/usb/serial/xr_serial.c | 151 ++++++++++++++++++++++++---------
> 1 file changed, 113 insertions(+), 38 deletions(-)

> static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id)
> {
> + struct xr_port_private *port_priv;
> +
> /* Don't bind to control interface */
> if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 0)
> return -ENODEV;
>
> + port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL);
> + if (!port_priv)
> + return -ENOMEM;

For historical reasons, you cannot allocate memory in probe() directly
(unless using devres) or this can leak on later probe errors.

Instead interface-wide allocations are done in attach() and released in
release(), while port-specific allocations are done in port_probe() and
released in port_remove().

Johan