* [PATCH 1/4] USB: usbfs: replace __get_free_page() with kmalloc()
2026-08-30 8:10 [PATCH 0/4] USB: replace page allocator calls with kmalloc() Mike Rapoport (Microsoft)
@ 2026-08-30 8:10 ` Mike Rapoport (Microsoft)
2026-08-30 8:10 ` [PATCH 2/4] USB: cxacru: " Mike Rapoport (Microsoft)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 8:10 UTC (permalink / raw)
To: Chas Williams, Duncan Sands, Greg Kroah-Hartman, Johan Hovold
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, accessrunner-general, linux-atm-general,
linux-kernel, linux-mm, linux-usb, netdev
do_proc_control() allocates a temporary buffer for the data stage of a
control transfer issued from userspace.
This buffer can be allocated with kmalloc() as there's nothing special
about it to go directly to the page allocator.
kmalloc() provides a better API that does not require ugly casts and
kfree() does not need to know the size of the freed object.
Performance difference between kmalloc() and __get_free_pages() is not
measurable as both allocators take an object/page from a per-CPU list for
fast path allocations.
For the slow path the performance is anyway determined by the amount of
reclaim involved rather than by what allocator is used.
Replace use of __get_free_page() with kmalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/usb/core/devio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 101cb9425480..9a7cc7cdf00b 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1190,7 +1190,7 @@ static int do_proc_control(struct usb_dev_state *ps,
return ret;
ret = -ENOMEM;
- tbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
+ tbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!tbuf)
goto done;
urb = usb_alloc_urb(0, GFP_NOIO);
@@ -1265,7 +1265,7 @@ static int do_proc_control(struct usb_dev_state *ps,
done:
kfree(dr);
usb_free_urb(urb);
- free_page((unsigned long) tbuf);
+ kfree(tbuf);
usbfs_decrease_memory_usage(PAGE_SIZE + sizeof(struct urb) +
sizeof(struct usb_ctrlrequest));
return ret;
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/4] USB: cxacru: replace __get_free_page() with kmalloc()
2026-08-30 8:10 [PATCH 0/4] USB: replace page allocator calls with kmalloc() Mike Rapoport (Microsoft)
2026-08-30 8:10 ` [PATCH 1/4] USB: usbfs: replace __get_free_page() " Mike Rapoport (Microsoft)
@ 2026-08-30 8:10 ` Mike Rapoport (Microsoft)
2026-08-30 8:10 ` [PATCH 3/4] USB: speedtch: " Mike Rapoport (Microsoft)
2026-08-30 8:10 ` [PATCH 4/4] USB: serial: wwan: " Mike Rapoport (Microsoft)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 8:10 UTC (permalink / raw)
To: Chas Williams, Duncan Sands, Greg Kroah-Hartman, Johan Hovold
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, accessrunner-general, linux-atm-general,
linux-kernel, linux-mm, linux-usb, netdev
cxacru_fw() allocates a temporary buffer used to feed the firmware to the
device and cxacru_bind() allocates the transfer buffers for the command
URBs.
These buffers can be allocated with kmalloc() as there's nothing special
about them to go directly to the page allocator.
kmalloc() provides a better API that does not require ugly casts and
kfree() does not need to know the size of the freed object.
Performance difference between kmalloc() and __get_free_pages() is not
measurable as both allocators take an object/page from a per-CPU list for
fast path allocations.
For the slow path the performance is anyway determined by the amount of
reclaim involved rather than by what allocator is used.
Replace use of __get_free_page() with kmalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/usb/atm/cxacru.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 636f7886fc26..75d87c31e81f 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -942,7 +942,7 @@ static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
int offd, offb;
const int stride = CMD_PACKET_SIZE - 8;
- buf = (u8 *) __get_free_page(GFP_KERNEL);
+ buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!buf)
return -ENOMEM;
@@ -978,7 +978,7 @@ static int cxacru_fw(struct usb_device *usb_dev, enum cxacru_fw_request fw,
ret = 0;
cleanup:
- free_page((unsigned long) buf);
+ kfree(buf);
return ret;
}
@@ -1146,13 +1146,13 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance,
mutex_init(&instance->adsl_state_serialize);
- instance->rcv_buf = (u8 *) __get_free_page(GFP_KERNEL);
+ instance->rcv_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!instance->rcv_buf) {
usb_dbg(usbatm_instance, "cxacru_bind: no memory for rcv_buf\n");
ret = -ENOMEM;
goto fail;
}
- instance->snd_buf = (u8 *) __get_free_page(GFP_KERNEL);
+ instance->snd_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!instance->snd_buf) {
usb_dbg(usbatm_instance, "cxacru_bind: no memory for snd_buf\n");
ret = -ENOMEM;
@@ -1220,8 +1220,8 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance,
return 0;
fail:
- free_page((unsigned long) instance->snd_buf);
- free_page((unsigned long) instance->rcv_buf);
+ kfree(instance->snd_buf);
+ kfree(instance->rcv_buf);
usb_free_urb(instance->snd_urb);
usb_free_urb(instance->rcv_urb);
kfree(instance);
@@ -1254,8 +1254,8 @@ static void cxacru_unbind(struct usbatm_data *usbatm_instance,
usb_free_urb(instance->snd_urb);
usb_free_urb(instance->rcv_urb);
- free_page((unsigned long) instance->snd_buf);
- free_page((unsigned long) instance->rcv_buf);
+ kfree(instance->snd_buf);
+ kfree(instance->rcv_buf);
kfree(instance);
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 3/4] USB: speedtch: replace __get_free_page() with kmalloc()
2026-08-30 8:10 [PATCH 0/4] USB: replace page allocator calls with kmalloc() Mike Rapoport (Microsoft)
2026-08-30 8:10 ` [PATCH 1/4] USB: usbfs: replace __get_free_page() " Mike Rapoport (Microsoft)
2026-08-30 8:10 ` [PATCH 2/4] USB: cxacru: " Mike Rapoport (Microsoft)
@ 2026-08-30 8:10 ` Mike Rapoport (Microsoft)
2026-08-30 8:10 ` [PATCH 4/4] USB: serial: wwan: " Mike Rapoport (Microsoft)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 8:10 UTC (permalink / raw)
To: Chas Williams, Duncan Sands, Greg Kroah-Hartman, Johan Hovold
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, accessrunner-general, linux-atm-general,
linux-kernel, linux-mm, linux-usb, netdev
speedtch_upload_firmware() allocates a temporary buffer used to feed the
firmware to the device.
This buffer can be allocated with kmalloc() as there's nothing special
about it to go directly to the page allocator.
kmalloc() provides a better API that does not require ugly casts and
kfree() does not need to know the size of the freed object.
Performance difference between kmalloc() and __get_free_pages() is not
measurable as both allocators take an object/page from a per-CPU list for
fast path allocations.
For the slow path the performance is anyway determined by the amount of
reclaim involved rather than by what allocator is used.
Replace use of __get_free_page() with kmalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/usb/atm/speedtch.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 9d28c652bcd8..e5e021aafbd3 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -241,7 +241,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
usb_dbg(usbatm, "%s entered\n", __func__);
- buffer = (unsigned char *)__get_free_page(GFP_KERNEL);
+ buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!buffer) {
ret = -ENOMEM;
usb_dbg(usbatm, "%s: no memory for buffer!\n", __func__);
@@ -340,7 +340,7 @@ static int speedtch_upload_firmware(struct speedtch_instance_data *instance,
ret = 0;
out_free:
- free_page((unsigned long)buffer);
+ kfree(buffer);
out:
return ret;
}
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 4/4] USB: serial: wwan: replace __get_free_page() with kmalloc()
2026-08-30 8:10 [PATCH 0/4] USB: replace page allocator calls with kmalloc() Mike Rapoport (Microsoft)
` (2 preceding siblings ...)
2026-08-30 8:10 ` [PATCH 3/4] USB: speedtch: " Mike Rapoport (Microsoft)
@ 2026-08-30 8:10 ` Mike Rapoport (Microsoft)
3 siblings, 0 replies; 5+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-08-30 8:10 UTC (permalink / raw)
To: Chas Williams, Duncan Sands, Greg Kroah-Hartman, Johan Hovold
Cc: Andrew Morton, David Hildenbrand, Matthew Wilcox, Mike Rapoport,
Vlastimil Babka, accessrunner-general, linux-atm-general,
linux-kernel, linux-mm, linux-usb, netdev
usb_wwan_port_probe() allocates the transfer buffers for the read URBs.
These buffers can be allocated with kmalloc() as there's nothing special
about them to go directly to the page allocator.
kmalloc() provides a better API that does not require ugly casts and
kfree() does not need to know the size of the freed object.
Performance difference between kmalloc() and __get_free_pages() is not
measurable as both allocators take an object/page from a per-CPU list for
fast path allocations.
For the slow path the performance is anyway determined by the amount of
reclaim involved rather than by what allocator is used.
While on it, allocate IN_BUFLEN bytes rather than a full page. IN_BUFLEN
is the transfer_buffer_length of the read URBs, the page allocator was
only used because IN_BUFLEN happens to equal PAGE_SIZE on x86.
Replace use of __get_free_page() with kmalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Assisted-by: copilot:claude-opus
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/usb/serial/usb_wwan.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index a183cc4515ed..a3929d3a3ec1 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -455,7 +455,7 @@ int usb_wwan_port_probe(struct usb_serial_port *port)
init_usb_anchor(&portdata->delayed);
for (i = 0; i < N_IN_URB; i++) {
- buffer = (u8 *)__get_free_page(GFP_KERNEL);
+ buffer = kmalloc(IN_BUFLEN, GFP_KERNEL);
if (!buffer)
goto bail_out_error;
portdata->in_buffer[i] = buffer;
@@ -492,7 +492,7 @@ int usb_wwan_port_probe(struct usb_serial_port *port)
bail_out_error:
for (i = 0; i < N_IN_URB; i++) {
usb_free_urb(portdata->in_urbs[i]);
- free_page((unsigned long)portdata->in_buffer[i]);
+ kfree(portdata->in_buffer[i]);
}
kfree(portdata);
@@ -510,7 +510,7 @@ void usb_wwan_port_remove(struct usb_serial_port *port)
for (i = 0; i < N_IN_URB; i++) {
usb_free_urb(portdata->in_urbs[i]);
- free_page((unsigned long)portdata->in_buffer[i]);
+ kfree(portdata->in_buffer[i]);
}
for (i = 0; i < N_OUT_URB; i++) {
usb_free_urb(portdata->out_urbs[i]);
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread