Skip to content

Commit 6559604

Browse files
bwhacksgregkh
authored andcommitted
catc: Use heap buffer for memory size test
commit 2d6a0e9de03ee658a9adc3bfb2f0ca55dff1e478 upstream. Allocating USB buffers on the stack is not portable, and no longer works on x86_64 (with VMAP_STACK enabled as per default). Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net> Cc: Brad Spengler <spender@grsecurity.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 40531b2 commit 6559604

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

drivers/net/usb/catc.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
777777
struct net_device *netdev;
778778
struct catc *catc;
779779
u8 broadcast[ETH_ALEN];
780-
int i, pktsz, ret;
780+
int pktsz, ret;
781781

782782
if (usb_set_interface(usbdev,
783783
intf->altsetting->desc.bInterfaceNumber, 1)) {
@@ -841,15 +841,24 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
841841
catc->irq_buf, 2, catc_irq_done, catc, 1);
842842

843843
if (!catc->is_f5u011) {
844+
u32 *buf;
845+
int i;
846+
844847
dev_dbg(dev, "Checking memory size\n");
845848

846-
i = 0x12345678;
847-
catc_write_mem(catc, 0x7a80, &i, 4);
848-
i = 0x87654321;
849-
catc_write_mem(catc, 0xfa80, &i, 4);
850-
catc_read_mem(catc, 0x7a80, &i, 4);
849+
buf = kmalloc(4, GFP_KERNEL);
850+
if (!buf) {
851+
ret = -ENOMEM;
852+
goto fail_free;
853+
}
854+
855+
*buf = 0x12345678;
856+
catc_write_mem(catc, 0x7a80, buf, 4);
857+
*buf = 0x87654321;
858+
catc_write_mem(catc, 0xfa80, buf, 4);
859+
catc_read_mem(catc, 0x7a80, buf, 4);
851860

852-
switch (i) {
861+
switch (*buf) {
853862
case 0x12345678:
854863
catc_set_reg(catc, TxBufCount, 8);
855864
catc_set_reg(catc, RxBufCount, 32);
@@ -864,6 +873,8 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
864873
dev_dbg(dev, "32k Memory\n");
865874
break;
866875
}
876+
877+
kfree(buf);
867878

868879
dev_dbg(dev, "Getting MAC from SEEROM.\n");
869880

0 commit comments

Comments
 (0)