can: usb_8dev: Fix memory leak of priv->cmd_msg_buffer
authorMarc Kleine-Budde <mkl@pengutronix.de>
Thu, 2 Mar 2017 11:03:40 +0000 (12:03 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Fri, 3 Mar 2017 12:00:07 +0000 (13:00 +0100)
The priv->cmd_msg_buffer is allocated in the probe function, but never
kfree()ed. This patch converts the kzalloc() to resource-managed
kzalloc.

Cc: linux-stable <stable@vger.kernel.org>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/usb_8dev.c

index 108a30e1509756fe571bb1d6fb6edbdf5dde25d7..d000cb62d6ae8c68233e123bc63686d3ab71dd67 100644 (file)
@@ -951,8 +951,8 @@ static int usb_8dev_probe(struct usb_interface *intf,
        for (i = 0; i < MAX_TX_URBS; i++)
                priv->tx_contexts[i].echo_index = MAX_TX_URBS;
 
-       priv->cmd_msg_buffer = kzalloc(sizeof(struct usb_8dev_cmd_msg),
-                                     GFP_KERNEL);
+       priv->cmd_msg_buffer = devm_kzalloc(&intf->dev, sizeof(struct usb_8dev_cmd_msg),
+                                           GFP_KERNEL);
        if (!priv->cmd_msg_buffer)
                goto cleanup_candev;
 
@@ -966,7 +966,7 @@ static int usb_8dev_probe(struct usb_interface *intf,
        if (err) {
                netdev_err(netdev,
                        "couldn't register CAN device: %d\n", err);
-               goto cleanup_cmd_msg_buffer;
+               goto cleanup_candev;
        }
 
        err = usb_8dev_cmd_version(priv, &version);
@@ -987,9 +987,6 @@ static int usb_8dev_probe(struct usb_interface *intf,
 cleanup_unregister_candev:
        unregister_netdev(priv->netdev);
 
-cleanup_cmd_msg_buffer:
-       kfree(priv->cmd_msg_buffer);
-
 cleanup_candev:
        free_candev(netdev);