Skip to content

Commit

Permalink
[media] go7007: don't continue if firmware can't be loaded
Browse files Browse the repository at this point in the history
The go7007 driver would continue during probe if no firmware could be
loaded. Without firmware the probe() should return an error, so do that.
Also move the registration of devices to the end of the probe() sequence:
once devices appear the full driver functionality should be available.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Mar 25, 2013
1 parent 7118b44 commit 59aea92
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
76 changes: 38 additions & 38 deletions drivers/staging/media/go7007/go7007-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,11 @@ static void go7007_usb_release(struct go7007 *go)
struct urb *vurb, *aurb;
int i;

usb_kill_urb(usb->intr_urb);
if (usb->intr_urb) {
usb_kill_urb(usb->intr_urb);
kfree(usb->intr_urb->transfer_buffer);
usb_free_urb(usb->intr_urb);
}

/* Free USB-related structs */
for (i = 0; i < 8; ++i) {
Expand All @@ -947,8 +951,6 @@ static void go7007_usb_release(struct go7007 *go)
usb_free_urb(aurb);
}
}
kfree(usb->intr_urb->transfer_buffer);
usb_free_urb(usb->intr_urb);

kfree(go->hpi_context);
}
Expand Down Expand Up @@ -1141,21 +1143,16 @@ static int go7007_usb_probe(struct usb_interface *intf,
return 0;
}

usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
if (usb == NULL)
go = go7007_alloc(&board->main_info, &intf->dev);
if (go == NULL)
return -ENOMEM;

/* Allocate the URB and buffer for receiving incoming interrupts */
usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
if (usb->intr_urb == NULL)
goto allocfail;
usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
if (usb->intr_urb->transfer_buffer == NULL)
goto allocfail;
usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
if (usb == NULL) {
kfree(go);
return -ENOMEM;
}

go = go7007_alloc(&board->main_info, &intf->dev);
if (go == NULL)
goto allocfail;
usb->board = board;
usb->usbdev = usbdev;
usb_make_path(usbdev, go->bus_info, sizeof(go->bus_info));
Expand All @@ -1166,6 +1163,15 @@ static int go7007_usb_probe(struct usb_interface *intf,
else
go->hpi_ops = &go7007_usb_onboard_hpi_ops;
go->hpi_context = usb;

/* Allocate the URB and buffer for receiving incoming interrupts */
usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
if (usb->intr_urb == NULL)
goto allocfail;
usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
if (usb->intr_urb->transfer_buffer == NULL)
goto allocfail;

if (go->board_id == GO7007_BOARDID_SENSORAY_2250)
usb_fill_bulk_urb(usb->intr_urb, usb->usbdev,
usb_rcvbulkpipe(usb->usbdev, 4),
Expand All @@ -1181,7 +1187,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
/* Boot the GO7007 */
if (go7007_boot_encoder(go, go->board_info->flags &
GO7007_BOARD_USE_ONBOARD_I2C) < 0)
goto initfail;
goto allocfail;

/* Register the EZ-USB I2C adapter, if we're using it */
if (board->flags & GO7007_USB_EZUSB_I2C) {
Expand All @@ -1193,7 +1199,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
if (i2c_add_adapter(&go->i2c_adapter) < 0) {
printk(KERN_ERR
"go7007-usb: error: i2c_add_adapter failed\n");
goto initfail;
goto allocfail;
}
go->i2c_adapter_online = 1;
}
Expand Down Expand Up @@ -1244,7 +1250,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
/* Board strapping indicates tuner model */
if (go7007_usb_vendor_request(go, 0x41, 0, 0, go->usb_buf, 3, 1) < 0) {
printk(KERN_ERR "go7007-usb: GPIO read failed!\n");
goto initfail;
goto allocfail;
}
switch (go->usb_buf[0] >> 6) {
case 1:
Expand Down Expand Up @@ -1276,7 +1282,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
NULL, 0, 0) < 0) {
printk(KERN_ERR "go7007-usb: GPIO write failed!\n");
goto initfail;
goto allocfail;
}
}

Expand All @@ -1290,11 +1296,6 @@ static int go7007_usb_probe(struct usb_interface *intf,
"port will result in stream corruption, even "
"at low bitrates!\n");

/* Do any final GO7007 initialization, then register the
* V4L2 and ALSA interfaces */
if (go7007_register_encoder(go, num_i2c_devs) < 0)
goto initfail;

/* Allocate the URBs and buffers for receiving the video stream */
if (board->flags & GO7007_USB_EZUSB) {
v_urb_len = 1024;
Expand All @@ -1306,46 +1307,45 @@ static int go7007_usb_probe(struct usb_interface *intf,
for (i = 0; i < 8; ++i) {
usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
if (usb->video_urbs[i] == NULL)
goto initfail;
goto allocfail;
usb->video_urbs[i]->transfer_buffer =
kmalloc(v_urb_len, GFP_KERNEL);
if (usb->video_urbs[i]->transfer_buffer == NULL)
goto initfail;
goto allocfail;
usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
usb->video_urbs[i]->transfer_buffer, v_urb_len,
go7007_usb_read_video_pipe_complete, go);
}

/* Allocate the URBs and buffers for receiving the audio stream */
if ((board->flags & GO7007_USB_EZUSB) && go->audio_enabled)
if ((board->flags & GO7007_USB_EZUSB) &&
(board->flags & GO7007_BOARD_HAS_AUDIO)) {
for (i = 0; i < 8; ++i) {
usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
if (usb->audio_urbs[i] == NULL)
goto initfail;
goto allocfail;
usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
GFP_KERNEL);
if (usb->audio_urbs[i]->transfer_buffer == NULL)
goto initfail;
goto allocfail;
usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
usb_rcvbulkpipe(usb->usbdev, 8),
usb->audio_urbs[i]->transfer_buffer, 4096,
go7007_usb_read_audio_pipe_complete, go);
}
}

/* Do any final GO7007 initialization, then register the
* V4L2 and ALSA interfaces */
if (go7007_register_encoder(go, num_i2c_devs) < 0)
goto allocfail;

go->status = STATUS_ONLINE;
return 0;

initfail:
go->status = STATUS_SHUTDOWN;
return 0;

allocfail:
if (usb->intr_urb) {
kfree(usb->intr_urb->transfer_buffer);
usb_free_urb(usb->intr_urb);
}
kfree(usb);
go7007_usb_release(go);
kfree(go);
return -ENOMEM;
}

Expand Down
34 changes: 17 additions & 17 deletions drivers/staging/media/go7007/saa7134-go7007.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,22 @@ static int saa7134_go7007_init(struct saa7134_dev *dev)

printk(KERN_DEBUG "saa7134-go7007: probing new SAA713X board\n");

go = go7007_alloc(&board_voyager, &dev->pci->dev);
if (go == NULL)
return -ENOMEM;

saa = kzalloc(sizeof(struct saa7134_go7007), GFP_KERNEL);
if (saa == NULL)
if (saa == NULL) {
kfree(go);
return -ENOMEM;
}

go->board_id = GO7007_BOARDID_PCI_VOYAGER;
snprintf(go->bus_info, sizeof(go->bus_info), "PCI:%s", pci_name(dev->pci));
strncpy(go->name, saa7134_boards[dev->board].name, sizeof(go->name));
go->hpi_ops = &saa7134_go7007_hpi_ops;
go->hpi_context = saa;
saa->dev = dev;

/* Init the subdevice interface */
sd = &saa->sd;
Expand All @@ -472,25 +485,15 @@ static int saa7134_go7007_init(struct saa7134_dev *dev)
if (!saa->bottom)
goto allocfail;

go = go7007_alloc(&board_voyager, &dev->pci->dev);
if (go == NULL)
goto allocfail;
go->board_id = GO7007_BOARDID_PCI_VOYAGER;
snprintf(go->bus_info, sizeof(go->bus_info), "PCI:%s", pci_name(dev->pci));
strncpy(go->name, saa7134_boards[dev->board].name, sizeof(go->name));
go->hpi_ops = &saa7134_go7007_hpi_ops;
go->hpi_context = saa;
saa->dev = dev;

/* Boot the GO7007 */
if (go7007_boot_encoder(go, go->board_info->flags &
GO7007_BOARD_USE_ONBOARD_I2C) < 0)
goto initfail;
goto allocfail;

/* Do any final GO7007 initialization, then register the
* V4L2 and ALSA interfaces */
if (go7007_register_encoder(go, go->board_info->num_i2c_devs) < 0)
goto initfail;
goto allocfail;

/* Register the subdevice interface with the go7007 device */
if (v4l2_device_register_subdev(&go->v4l2_dev, sd) < 0)
Expand All @@ -501,16 +504,13 @@ static int saa7134_go7007_init(struct saa7134_dev *dev)
go->status = STATUS_ONLINE;
return 0;

initfail:
go->status = STATUS_SHUTDOWN;
return 0;

allocfail:
if (saa->top)
free_page((unsigned long)saa->top);
if (saa->bottom)
free_page((unsigned long)saa->bottom);
kfree(saa);
kfree(go);
return -ENOMEM;
}

Expand Down

0 comments on commit 59aea92

Please sign in to comment.