Moved from manually allocated private data to alloc_candev.
* @see https://github.com/commaai/panda for the full project.
*/
-#include <linux/can.h>
#include <linux/can/dev.h>
#include <linux/can/error.h>
-#include <linux/can/led.h>
#include <linux/init.h> // Macros used to mark up functions e.g., __init __exit
-#include <linux/module.h> // Core header for loading LKMs into the kernel
#include <linux/kernel.h> // Contains types, macros, functions for the kernel
+#include <linux/module.h> // Core header for loading LKMs into the kernel
+#include <linux/netdevice.h>
#include <linux/usb.h>
/* vendor and product id */
#define PANDA_VENDOR_ID 0XBBAA
#define PANDA_PRODUCT_ID 0XDDCC
+// I don't get this yet
+#define MCBA_MAX_TX_URBS 20
+
static const struct usb_device_id panda_usb_table[] = {
{ USB_DEVICE(PANDA_VENDOR_ID, PANDA_PRODUCT_ID) },
{} /* Terminating entry */
};
struct panda_priv {
+ struct can_priv can;
+ struct usb_device *udev;
+ struct net_device *netdev;
+
unsigned int id;
};
@@ -41,15 +47,21 @@ static int panda_usb_start(struct panda_priv *priv)
static int panda_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
+ struct net_device *netdev;
+ struct panda_priv *priv;
int err = -ENOMEM;
- //struct usb_device *usbdev = interface_to_usbdev(intf);
- struct panda_priv *priv = NULL;
+ struct usb_device *usbdev = interface_to_usbdev(intf);
- /* Allocate space for device driver specific data */
- priv = kzalloc(sizeof(struct panda_priv), GFP_KERNEL);
- if (!priv)
+ netdev = alloc_candev(sizeof(struct panda_priv), MCBA_MAX_TX_URBS);
+ if (!netdev) {
+ dev_err(&intf->dev, "Couldn't alloc candev\n");
return -ENOMEM;
+ }
+
+ priv = netdev_priv(netdev);
+ priv->udev = usbdev;
+ priv->netdev = netdev;
priv->id = curr_id++;
usb_set_intfdata(intf, priv);
@@ -57,15 +69,15 @@ static int panda_usb_probe(struct usb_interface *intf,
err = panda_usb_start(priv);
if (err) {
dev_info(&intf->dev, "Failed to initialize Comma.ai Panda CAN controller\n");
- goto cleanup;
+ goto cleanup_free_candev;
}
dev_info(&intf->dev, "Comma.ai Panda CAN controller connected (ID: %u)\n", priv->id);
return 0;
- cleanup:
- kfree(priv);
+ cleanup_free_candev:
+ free_candev(priv->netdev);
return err;
}
@@ -78,13 +90,7 @@ static void panda_usb_disconnect(struct usb_interface *intf)
dev_info(&intf->dev, "Removed Comma.ai Panda CAN controller (ID: %u)\n", priv->id);
- //netdev_info(priv->netdev, "device disconnected\n");
- //
- //unregister_candev(priv->netdev);
- //free_candev(priv->netdev);
- //
- //mcba_urb_unlink(priv);
- kfree(priv);
+ free_candev(priv->netdev);
}
static struct usb_driver panda_usb_driver = {
