Thread (5 messages) 5 messages, 3 authors, 2012-01-10

Re: [PATCH] Add support for PEAK System PCAN-USB adapter

From: Sebastian Haas <hidden>
Date: 2011-12-26 14:21:15

Hi Stéphane,

Am 26.12.2011 12:08, schrieb Grosjean Stephane:
quoted
quoted
+/*
+ * start interface
+ */
+static int pcan_usb_start(struct peak_usb_device *dev)
+{
+ struct pcan_usb *pdev = (struct pcan_usb *)dev;
+ int err;
Initialize err with 0 here.
Why?
You are right. Forget it.
quoted
quoted
+
+ /* number of bits used in timestamps read from adapter struct */
+ peak_usb_init_time_ref(&pdev->time_ref,&pcan_usb);
+
+ /* if revision greater than 3, can put silent mode on/off */
+ if (dev->device_rev> 3) {
+ err = pcan_usb_set_silent(dev,
+ (dev->can.ctrlmode& CAN_CTRLMODE_LISTENONLY));
Remove useless brackets for ctrlmode & LISTENONLY are useless.
Ok.
quoted
quoted
+ if (err)
+ goto start_failed;
Return with err.
Ok.
quoted
quoted
+ }
+
+ err = pcan_usb_set_ext_vcc(dev, 0);
+ if (err)
+ goto start_failed;
+
+ return 0;
+
+start_failed:
Remove the 6 lines above.
Ok.
quoted
quoted
+ return err;
+}
So, what do you think about that:

/*
* start interface
*/
static int pcan_usb_start(struct peak_usb_device *dev)
{
struct pcan_usb *pdev = (struct pcan_usb *)dev;

/* number of bits used in timestamps read from adapter struct */
peak_usb_init_time_ref(&pdev->time_ref, &pcan_usb);

/* if revision greater than 3, can put silent mode on/off */
if (dev->device_rev > 3) {
int err;

err = pcan_usb_set_silent(dev,
dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY);
if (err)
return err;
}

return pcan_usb_set_ext_vcc(dev, 0);
}

?
Much more cleaner. Thanks.

Cheers,
  Sebastian
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help