[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[MiNT] [PATCH] Check return values from kmallocs in usb.c
Commit message:
Add checks for return values from kmalloc.
? .hg
? .hgignore
Index: sys/usb/src.km/usb.c
===================================================================
RCS file: /mint/freemint/sys/usb/src.km/usb.c,v
retrieving revision 1.16
diff -u -8 -r1.16 usb.c
--- sys/usb/src.km/usb.c 5 Oct 2014 19:45:58 -0000 1.16
+++ sys/usb/src.km/usb.c 6 Oct 2014 08:05:16 -0000
@@ -472,31 +472,39 @@
long usb_get_configuration_no(struct usb_device *dev, long cfgno)
{
unsigned char *buffer;
long result, err;
unsigned long tmp;
struct usb_config_descriptor *config;
config = (struct usb_config_descriptor *)kmalloc(9);
+ if (!config) {
+ DEBUG(("Out of memory"));
+ return -1;
+ }
result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, config, 9);
if (result < 9) {
if (result < 0)
DEBUG(("unable to get descriptor, error %lx",
dev->status));
else
DEBUG(("config descriptor too short " \
"(expected %i, got %i)", 9, result));
kfree(config);
return -1;
}
tmp = le2cpu16(config->wTotalLength);
kfree(config);
buffer = (unsigned char*)kmalloc(tmp);
+ if (!buffer) {
+ DEBUG(("Out of memory"));
+ return -1;
+ }
result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, tmp);
DEBUG(("get_conf_no %ld Result %ld, wLength %ld",
cfgno, result, tmp));
err = usb_parse_config(dev, buffer, 0);
if (err < 0) {
DEBUG(("usb_new_device: Cannot parse configuration, " \
"skipping device %04x:%04x\n",
@@ -876,16 +884,20 @@
addr = dev->devnum;
dev->devnum = 0;
/* send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is
* only 18 bytes long, this will terminate with a short packet. But if
* the maxpacket size is 8 or 16 the device may be waiting to transmit
* some more, or keeps on retransmitting the 8 byte header. */
desc = (struct usb_device_descriptor *)kmalloc(64);
+ if (!desc) {
+ DEBUG(("Out of memory"));
+ return -1;
+ }
dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */
/* Default to 64 byte max packet size */
dev->maxpacketsize = PACKET_SIZE_64;
dev->epmaxpacketin[0] = 64;
dev->epmaxpacketout[0] = 64;
@@ -960,16 +972,20 @@
"(error=%lx)", dev->status));
return 1;
}
mdelay(200); /* Let the SET_ADDRESS settle */
tmp = sizeof(dev->descriptor);
tmpbuf = (unsigned char *)kmalloc(tmp);
+ if (!tmpbuf) {
+ DEBUG(("Out of memory"));
+ return -1;
+ }
err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, tmpbuf, tmp);
if (err < tmp) {
if (err < 0)
DEBUG(("unable to get device descriptor (error=%ld)",
err));
else
DEBUG(("USB device descriptor short read " \