Skip to content

Commit 48051c3

Browse files
committed
Merge tag 'linux-can-fixes-for-4.11-20170303' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says: ==================== pull-request: can 2017-03-03 this is a pull request for the upcoming v4.11 release. There are two patches by Ethan Zonca for the gs_usb driver, the first one fixes the memory used for USB transfers, the second one the coding style. The last two patches are by me, one fixing a memory leak in the usb_8dev driver the other a typo in the flexcan driver. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents a8d63a5 + 66ddb82 commit 48051c3

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

drivers/net/can/flexcan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
#define FLEXCAN_QUIRK_BROKEN_ERR_STATE BIT(1) /* [TR]WRN_INT not connected */
197197
#define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2) /* Disable RX FIFO Global mask */
198198
#define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3) /* Enable EACEN and RRS bit in ctrl2 */
199-
#define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) /* Disble Memory error detection */
199+
#define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) /* Disable Memory error detection */
200200
#define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5) /* Use timestamp based offloading */
201201

202202
/* Structure of the message buffer */

drivers/net/can/usb/gs_usb.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int gs_cmd_reset(struct gs_usb *gsusb, struct gs_can *gsdev)
258258
rc = usb_control_msg(interface_to_usbdev(intf),
259259
usb_sndctrlpipe(interface_to_usbdev(intf), 0),
260260
GS_USB_BREQ_MODE,
261-
USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
261+
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
262262
gsdev->channel,
263263
0,
264264
dm,
@@ -432,7 +432,7 @@ static int gs_usb_set_bittiming(struct net_device *netdev)
432432
rc = usb_control_msg(interface_to_usbdev(intf),
433433
usb_sndctrlpipe(interface_to_usbdev(intf), 0),
434434
GS_USB_BREQ_BITTIMING,
435-
USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
435+
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
436436
dev->channel,
437437
0,
438438
dbt,
@@ -546,7 +546,6 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb,
546546
hf,
547547
urb->transfer_dma);
548548

549-
550549
if (rc == -ENODEV) {
551550
netif_device_detach(netdev);
552551
} else {
@@ -804,7 +803,7 @@ static struct gs_can *gs_make_candev(unsigned int channel,
804803
rc = usb_control_msg(interface_to_usbdev(intf),
805804
usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
806805
GS_USB_BREQ_BT_CONST,
807-
USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
806+
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
808807
channel,
809808
0,
810809
bt_const,
@@ -908,57 +907,72 @@ static int gs_usb_probe(struct usb_interface *intf,
908907
struct gs_usb *dev;
909908
int rc = -ENOMEM;
910909
unsigned int icount, i;
911-
struct gs_host_config hconf = {
912-
.byte_order = 0x0000beef,
913-
};
914-
struct gs_device_config dconf;
910+
struct gs_host_config *hconf;
911+
struct gs_device_config *dconf;
912+
913+
hconf = kmalloc(sizeof(*hconf), GFP_KERNEL);
914+
if (!hconf)
915+
return -ENOMEM;
916+
917+
hconf->byte_order = 0x0000beef;
915918

916919
/* send host config */
917920
rc = usb_control_msg(interface_to_usbdev(intf),
918921
usb_sndctrlpipe(interface_to_usbdev(intf), 0),
919922
GS_USB_BREQ_HOST_FORMAT,
920-
USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
923+
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
921924
1,
922925
intf->altsetting[0].desc.bInterfaceNumber,
923-
&hconf,
924-
sizeof(hconf),
926+
hconf,
927+
sizeof(*hconf),
925928
1000);
926929

930+
kfree(hconf);
931+
927932
if (rc < 0) {
928933
dev_err(&intf->dev, "Couldn't send data format (err=%d)\n",
929934
rc);
930935
return rc;
931936
}
932937

938+
dconf = kmalloc(sizeof(*dconf), GFP_KERNEL);
939+
if (!dconf)
940+
return -ENOMEM;
941+
933942
/* read device config */
934943
rc = usb_control_msg(interface_to_usbdev(intf),
935944
usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
936945
GS_USB_BREQ_DEVICE_CONFIG,
937-
USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
946+
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
938947
1,
939948
intf->altsetting[0].desc.bInterfaceNumber,
940-
&dconf,
941-
sizeof(dconf),
949+
dconf,
950+
sizeof(*dconf),
942951
1000);
943952
if (rc < 0) {
944953
dev_err(&intf->dev, "Couldn't get device config: (err=%d)\n",
945954
rc);
955+
kfree(dconf);
946956
return rc;
947957
}
948958

949-
icount = dconf.icount + 1;
959+
icount = dconf->icount + 1;
950960
dev_info(&intf->dev, "Configuring for %d interfaces\n", icount);
951961

952962
if (icount > GS_MAX_INTF) {
953963
dev_err(&intf->dev,
954964
"Driver cannot handle more that %d CAN interfaces\n",
955965
GS_MAX_INTF);
966+
kfree(dconf);
956967
return -EINVAL;
957968
}
958969

959970
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
960-
if (!dev)
971+
if (!dev) {
972+
kfree(dconf);
961973
return -ENOMEM;
974+
}
975+
962976
init_usb_anchor(&dev->rx_submitted);
963977

964978
atomic_set(&dev->active_channels, 0);
@@ -967,7 +981,7 @@ static int gs_usb_probe(struct usb_interface *intf,
967981
dev->udev = interface_to_usbdev(intf);
968982

969983
for (i = 0; i < icount; i++) {
970-
dev->canch[i] = gs_make_candev(i, intf, &dconf);
984+
dev->canch[i] = gs_make_candev(i, intf, dconf);
971985
if (IS_ERR_OR_NULL(dev->canch[i])) {
972986
/* save error code to return later */
973987
rc = PTR_ERR(dev->canch[i]);
@@ -978,12 +992,15 @@ static int gs_usb_probe(struct usb_interface *intf,
978992
gs_destroy_candev(dev->canch[i]);
979993

980994
usb_kill_anchored_urbs(&dev->rx_submitted);
995+
kfree(dconf);
981996
kfree(dev);
982997
return rc;
983998
}
984999
dev->canch[i]->parent = dev;
9851000
}
9861001

1002+
kfree(dconf);
1003+
9871004
return 0;
9881005
}
9891006

drivers/net/can/usb/usb_8dev.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ static int usb_8dev_probe(struct usb_interface *intf,
951951
for (i = 0; i < MAX_TX_URBS; i++)
952952
priv->tx_contexts[i].echo_index = MAX_TX_URBS;
953953

954-
priv->cmd_msg_buffer = kzalloc(sizeof(struct usb_8dev_cmd_msg),
955-
GFP_KERNEL);
954+
priv->cmd_msg_buffer = devm_kzalloc(&intf->dev, sizeof(struct usb_8dev_cmd_msg),
955+
GFP_KERNEL);
956956
if (!priv->cmd_msg_buffer)
957957
goto cleanup_candev;
958958

@@ -966,7 +966,7 @@ static int usb_8dev_probe(struct usb_interface *intf,
966966
if (err) {
967967
netdev_err(netdev,
968968
"couldn't register CAN device: %d\n", err);
969-
goto cleanup_cmd_msg_buffer;
969+
goto cleanup_candev;
970970
}
971971

972972
err = usb_8dev_cmd_version(priv, &version);
@@ -987,9 +987,6 @@ static int usb_8dev_probe(struct usb_interface *intf,
987987
cleanup_unregister_candev:
988988
unregister_netdev(priv->netdev);
989989

990-
cleanup_cmd_msg_buffer:
991-
kfree(priv->cmd_msg_buffer);
992-
993990
cleanup_candev:
994991
free_candev(netdev);
995992

0 commit comments

Comments
 (0)