lkml.org 
[lkml]   [2021]   [Mar]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 2/7] USB: serial: xr: use a table for device-specific settings
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@kernel.org>
> ---
> 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

\
 
 \ /
  Last update: 2021-03-30 16:46    [W:0.077 / U:26.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site