svn commit: r363420 - in head/sys: compat/linuxkpi/common/src dev/sound/usb dev/usb dev/usb/input dev/usb/storage
Mark Johnston
markj at FreeBSD.org
Wed Jul 22 14:32:50 UTC 2020
Author: markj
Date: Wed Jul 22 14:32:47 2020
New Revision: 363420
URL: https://svnweb.freebsd.org/changeset/base/363420
Log:
usb(4): Stop checking for failures from malloc(M_WAITOK).
Handle the fact that parts of usb(4) can be compiled into the boot
loader, where M_WAITOK does not guarantee a successful allocation.
PR: 240545
Submitted by: Andrew Reiter <arr at watson.org> (original version)
Reviewed by: hselasky
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D25706
Modified:
head/sys/compat/linuxkpi/common/src/linux_usb.c
head/sys/dev/sound/usb/uaudio.c
head/sys/dev/usb/input/uhid.c
head/sys/dev/usb/input/uhid_snes.c
head/sys/dev/usb/storage/ustorage_fs.c
head/sys/dev/usb/usb_dev.c
head/sys/dev/usb/usb_device.c
head/sys/dev/usb/usb_freebsd.h
head/sys/dev/usb/usb_freebsd_loader.h
head/sys/dev/usb/usb_generic.c
head/sys/dev/usb/usb_mbuf.c
head/sys/dev/usb/usb_transfer.c
Modified: head/sys/compat/linuxkpi/common/src/linux_usb.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_usb.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/compat/linuxkpi/common/src/linux_usb.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -707,8 +707,6 @@ usb_control_msg(struct usb_device *dev, struct usb_hos
* 0xFFFF is a FreeBSD specific magic value.
*/
urb = usb_alloc_urb(0xFFFF, size);
- if (urb == NULL)
- return (-ENOMEM);
urb->dev = dev;
urb->endpoint = uhe;
@@ -1008,16 +1006,14 @@ usb_alloc_urb(uint16_t iso_packets, uint16_t mem_flags
}
urb = malloc(size, M_USBDEV, M_WAITOK | M_ZERO);
- if (urb) {
- cv_init(&urb->cv_wait, "URBWAIT");
- if (iso_packets == 0xFFFF) {
- urb->setup_packet = (void *)(urb + 1);
- urb->transfer_buffer = (void *)(urb->setup_packet +
- sizeof(struct usb_device_request));
- } else {
- urb->number_of_packets = iso_packets;
- }
+ cv_init(&urb->cv_wait, "URBWAIT");
+ if (iso_packets == 0xFFFF) {
+ urb->setup_packet = (void *)(urb + 1);
+ urb->transfer_buffer = (void *)(urb->setup_packet +
+ sizeof(struct usb_device_request));
+ } else {
+ urb->number_of_packets = iso_packets;
}
return (urb);
}
@@ -1722,8 +1718,6 @@ usb_bulk_msg(struct usb_device *udev, struct usb_host_
return (err);
urb = usb_alloc_urb(0, 0);
- if (urb == NULL)
- return (-ENOMEM);
usb_fill_bulk_urb(urb, udev, uhe, data, len,
usb_linux_wait_complete, NULL);
Modified: head/sys/dev/sound/usb/uaudio.c
==============================================================================
--- head/sys/dev/sound/usb/uaudio.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/sound/usb/uaudio.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -4968,10 +4968,6 @@ uaudio_mixer_fill_info(struct uaudio_softc *sc,
iot = malloc(sizeof(struct uaudio_terminal_node) * 256, M_TEMP,
M_WAITOK | M_ZERO);
- if (iot == NULL) {
- DPRINTF("no memory!\n");
- goto done;
- }
while ((desc = usb_desc_foreach(cd, desc))) {
dp = desc;
Modified: head/sys/dev/usb/input/uhid.c
==============================================================================
--- head/sys/dev/usb/input/uhid.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/input/uhid.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -451,10 +451,6 @@ uhid_get_report(struct uhid_softc *sc, uint8_t type,
if (kern_data == NULL) {
kern_data = malloc(len, M_USBDEV, M_WAITOK);
- if (kern_data == NULL) {
- err = ENOMEM;
- goto done;
- }
free_data = 1;
}
err = usbd_req_get_report(sc->sc_udev, NULL, kern_data,
@@ -487,10 +483,6 @@ uhid_set_report(struct uhid_softc *sc, uint8_t type,
if (kern_data == NULL) {
kern_data = malloc(len, M_USBDEV, M_WAITOK);
- if (kern_data == NULL) {
- err = ENOMEM;
- goto done;
- }
free_data = 1;
err = copyin(user_data, kern_data, len);
if (err) {
Modified: head/sys/dev/usb/input/uhid_snes.c
==============================================================================
--- head/sys/dev/usb/input/uhid_snes.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/input/uhid_snes.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -168,10 +168,6 @@ uhid_get_report(struct uhid_snes_softc *sc, uint8_t ty
if (kern_data == NULL) {
kern_data = malloc(len, M_USBDEV, M_WAITOK);
- if (kern_data == NULL) {
- err = ENOMEM;
- goto done;
- }
free_data = 1;
}
err = usbd_req_get_report(sc->sc_udev, NULL, kern_data,
@@ -203,10 +199,6 @@ uhid_set_report(struct uhid_snes_softc *sc, uint8_t ty
if (kern_data == NULL) {
kern_data = malloc(len, M_USBDEV, M_WAITOK);
- if (kern_data == NULL) {
- err = ENOMEM;
- goto done;
- }
free_data = 1;
err = copyin(user_data, kern_data, len);
if (err) {
Modified: head/sys/dev/usb/storage/ustorage_fs.c
==============================================================================
--- head/sys/dev/usb/storage/ustorage_fs.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/storage/ustorage_fs.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -381,10 +381,6 @@ ustorage_fs_attach(device_t dev)
ustorage_fs_ramdisk =
malloc(USTORAGE_FS_RAM_SECT << 9, M_USB,
M_ZERO | M_WAITOK);
-
- if (ustorage_fs_ramdisk == NULL) {
- return (ENOMEM);
- }
}
sc->sc_lun[0].memory_image = ustorage_fs_ramdisk;
sc->sc_lun[0].num_sectors = USTORAGE_FS_RAM_SECT;
Modified: head/sys/dev/usb/usb_dev.c
==============================================================================
--- head/sys/dev/usb/usb_dev.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/usb_dev.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -386,13 +386,11 @@ usb_fifo_alloc(struct mtx *mtx)
struct usb_fifo *f;
f = malloc(sizeof(*f), M_USBDEV, M_WAITOK | M_ZERO);
- if (f != NULL) {
- cv_init(&f->cv_io, "FIFO-IO");
- cv_init(&f->cv_drain, "FIFO-DRAIN");
- f->priv_mtx = mtx;
- f->refcount = 1;
- knlist_init_mtx(&f->selinfo.si_note, mtx);
- }
+ cv_init(&f->cv_io, "FIFO-IO");
+ cv_init(&f->cv_drain, "FIFO-DRAIN");
+ f->priv_mtx = mtx;
+ f->refcount = 1;
+ knlist_init_mtx(&f->selinfo.si_note, mtx);
return (f);
}
@@ -2309,9 +2307,6 @@ usb_alloc_symlink(const char *target)
struct usb_symlink *ps;
ps = malloc(sizeof(*ps), M_USBDEV, M_WAITOK);
- if (ps == NULL) {
- return (ps);
- }
/* XXX no longer needed */
strlcpy(ps->src_path, target, sizeof(ps->src_path));
ps->src_len = strlen(ps->src_path);
Modified: head/sys/dev/usb/usb_device.c
==============================================================================
--- head/sys/dev/usb/usb_device.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/usb_device.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -1785,9 +1785,11 @@ usb_alloc_device(device_t parent_dev, struct usb_bus *
return (NULL);
}
udev = malloc(sizeof(*udev), M_USB, M_WAITOK | M_ZERO);
+#if (USB_HAVE_MALLOC_WAITOK == 0)
if (udev == NULL) {
return (NULL);
}
+#endif
/* initialise our SX-lock */
sx_init_flags(&udev->enum_sx, "USB config SX lock", SX_DUPOK);
sx_init_flags(&udev->sr_sx, "USB suspend and resume SX lock", SX_NOWITNESS);
Modified: head/sys/dev/usb/usb_freebsd.h
==============================================================================
--- head/sys/dev/usb/usb_freebsd.h Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/usb_freebsd.h Wed Jul 22 14:32:47 2020 (r363420)
@@ -53,6 +53,7 @@
#define USB_HAVE_FIXED_CONFIG 0
#define USB_HAVE_FIXED_PORT 0
#define USB_HAVE_DISABLE_ENUM 1
+#define USB_HAVE_MALLOC_WAITOK 1
/* define zero ticks callout value */
#define USB_CALLOUT_ZERO_TICKS 1
Modified: head/sys/dev/usb/usb_freebsd_loader.h
==============================================================================
--- head/sys/dev/usb/usb_freebsd_loader.h Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/usb_freebsd_loader.h Wed Jul 22 14:32:47 2020 (r363420)
@@ -53,6 +53,7 @@
#define USB_HAVE_FIXED_CONFIG 0
#define USB_HAVE_FIXED_PORT 0
#define USB_HAVE_DISABLE_ENUM 0
+#define USB_HAVE_MALLOC_WAITOK 0
#define USB_CALLOUT_ZERO_TICKS 1
Modified: head/sys/dev/usb/usb_generic.c
==============================================================================
--- head/sys/dev/usb/usb_generic.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/usb_generic.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -2339,11 +2339,6 @@ ugen_ioctl_post(struct usb_fifo *f, u_long cmd, void *
}
f->fs_xfer = malloc(sizeof(f->fs_xfer[0]) *
u.pinit->ep_index_max, M_USB, M_WAITOK | M_ZERO);
- if (f->fs_xfer == NULL) {
- usb_fifo_free_buffer(f);
- error = ENOMEM;
- break;
- }
f->fs_ep_max = u.pinit->ep_index_max;
f->fs_ep_ptr = u.pinit->pEndpoints;
break;
Modified: head/sys/dev/usb/usb_mbuf.c
==============================================================================
--- head/sys/dev/usb/usb_mbuf.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/usb_mbuf.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -78,15 +78,10 @@ usb_alloc_mbufs(struct malloc_type *type, struct usb_i
alloc_size = (block_size + sizeof(struct usb_mbuf)) * nblocks;
free_ptr = malloc(alloc_size, type, M_WAITOK | M_ZERO);
-
- if (free_ptr == NULL) {
- goto done;
- }
m_ptr = free_ptr;
data_ptr = (void *)(m_ptr + nblocks);
while (nblocks--) {
-
m_ptr->cur_data_ptr =
m_ptr->min_data_ptr = data_ptr;
@@ -99,6 +94,5 @@ usb_alloc_mbufs(struct malloc_type *type, struct usb_i
data_ptr += block_size;
}
}
-done:
return (free_ptr);
}
Modified: head/sys/dev/usb/usb_transfer.c
==============================================================================
--- head/sys/dev/usb/usb_transfer.c Wed Jul 22 14:24:41 2020 (r363419)
+++ head/sys/dev/usb/usb_transfer.c Wed Jul 22 14:32:47 2020 (r363420)
@@ -1342,14 +1342,15 @@ usbd_transfer_setup(struct usb_device *udev,
/* allocate zeroed memory */
buf = malloc(parm->size[0], M_USB, M_WAITOK | M_ZERO);
-
+#if (USB_HAVE_MALLOC_WAITOK == 0)
if (buf == NULL) {
parm->err = USB_ERR_NOMEM;
DPRINTFN(0, "cannot allocate memory block for "
"configuration (%d bytes)\n",
parm->size[0]);
goto done;
- }
+ }
+#endif
parm->dma_tag_p = USB_ADD_BYTES(buf, parm->size[1]);
parm->dma_page_ptr = USB_ADD_BYTES(buf, parm->size[3]);
parm->dma_page_cache_ptr = USB_ADD_BYTES(buf, parm->size[4]);
More information about the svn-src-all
mailing list