mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 21:38:32 +08:00
USB: symbolserial: move private-data allocation to port_probe
Allocate port-private data in port-probe rather than in attach. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ef31025d68
commit
a85796ee51
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Symbol USB barcode to serial driver
|
||||
*
|
||||
* Copyright (C) 2013 Johan Hovold <jhovold@gmail.com>
|
||||
* Copyright (C) 2009 Greg Kroah-Hartman <gregkh@suse.de>
|
||||
* Copyright (C) 2009 Novell Inc.
|
||||
*
|
||||
@ -35,7 +36,7 @@ struct symbol_private {
|
||||
static void symbol_int_callback(struct urb *urb)
|
||||
{
|
||||
struct usb_serial_port *port = urb->context;
|
||||
struct symbol_private *priv = usb_get_serial_data(port->serial);
|
||||
struct symbol_private *priv = usb_get_serial_port_data(port);
|
||||
unsigned char *data = urb->transfer_buffer;
|
||||
int status = urb->status;
|
||||
int result;
|
||||
@ -153,30 +154,36 @@ static void symbol_unthrottle(struct tty_struct *tty)
|
||||
|
||||
static int symbol_startup(struct usb_serial *serial)
|
||||
{
|
||||
struct symbol_private *priv;
|
||||
|
||||
if (!serial->num_interrupt_in) {
|
||||
dev_err(&serial->dev->dev, "no interrupt-in endpoint\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* create our private serial structure */
|
||||
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
||||
if (priv == NULL) {
|
||||
dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
spin_lock_init(&priv->lock);
|
||||
|
||||
usb_set_serial_data(serial, priv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void symbol_release(struct usb_serial *serial)
|
||||
static int symbol_port_probe(struct usb_serial_port *port)
|
||||
{
|
||||
struct symbol_private *priv = usb_get_serial_data(serial);
|
||||
struct symbol_private *priv;
|
||||
|
||||
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_init(&priv->lock);
|
||||
|
||||
usb_set_serial_port_data(port, priv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int symbol_port_remove(struct usb_serial_port *port)
|
||||
{
|
||||
struct symbol_private *priv = usb_get_serial_port_data(port);
|
||||
|
||||
kfree(priv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct usb_serial_driver symbol_device = {
|
||||
@ -187,9 +194,10 @@ static struct usb_serial_driver symbol_device = {
|
||||
.id_table = id_table,
|
||||
.num_ports = 1,
|
||||
.attach = symbol_startup,
|
||||
.port_probe = symbol_port_probe,
|
||||
.port_remove = symbol_port_remove,
|
||||
.open = symbol_open,
|
||||
.close = symbol_close,
|
||||
.release = symbol_release,
|
||||
.throttle = symbol_throttle,
|
||||
.unthrottle = symbol_unthrottle,
|
||||
.read_int_callback = symbol_int_callback,
|
||||
|
Loading…
Reference in New Issue
Block a user