* [PATCH 1/4] serial: pch: replace __get_free_page() with kmalloc()
2026-05-28 10:24 [PATCH 0/4] tty: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
@ 2026-05-28 10:24 ` Mike Rapoport (Microsoft)
2026-05-28 10:24 ` [PATCH 2/4] tty: amiserial: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 10:24 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Mike Rapoport, linux-kernel, linux-mm, linux-serial
pch_uart_init_port() allocates a staging buffer for non-DMA receive path
using __get_free_page().
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.
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
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/tty/serial/pch_uart.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index 6729d8e83c3c..07d8cdb58912 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -1655,7 +1655,7 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
if (priv == NULL)
goto init_port_alloc_err;
- rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
+ rxbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!rxbuf)
goto init_port_free_txbuf;
@@ -1728,7 +1728,7 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
#ifdef CONFIG_SERIAL_PCH_UART_CONSOLE
pch_uart_ports[board->line_no] = NULL;
#endif
- free_page((unsigned long)rxbuf);
+ kfree(rxbuf);
init_port_free_txbuf:
kfree(priv);
init_port_alloc_err:
@@ -1743,7 +1743,7 @@ static void pch_uart_exit_port(struct eg20t_port *priv)
snprintf(name, sizeof(name), "uart%d_regs", priv->port.line);
debugfs_lookup_and_remove(name, NULL);
uart_remove_one_port(&pch_uart_driver, &priv->port);
- free_page((unsigned long)priv->rxbuf.buf);
+ kfree(priv->rxbuf.buf);
}
static void pch_uart_pci_remove(struct pci_dev *pdev)
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/4] tty: amiserial: replace get_zeroed_page() with kzalloc()
2026-05-28 10:24 [PATCH 0/4] tty: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
2026-05-28 10:24 ` [PATCH 1/4] serial: pch: replace __get_free_page() " Mike Rapoport (Microsoft)
@ 2026-05-28 10:24 ` Mike Rapoport (Microsoft)
2026-05-28 10:24 ` [PATCH 3/4] tty: serial: men_z135_uart: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
2026-05-28 10:24 ` [PATCH 4/4] vc_screen: replace __get_free_pages() " Mike Rapoport (Microsoft)
3 siblings, 0 replies; 9+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 10:24 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Mike Rapoport, linux-kernel, linux-mm, linux-serial
rs_startup() allocates a transmit ring buffer that is used to buffer reads
and writes from/to serial data register.
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.
Replace use of get_zeroed_page() with kzalloc() and free_page() with
kfree().
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/tty/amiserial.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 81eaca751541..28af0fd98181 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -443,23 +443,23 @@ static int rs_startup(struct tty_struct *tty, struct serial_state *info)
struct tty_port *port = &info->tport;
unsigned long flags;
int retval=0;
- unsigned long page;
+ void *buffer;
- page = get_zeroed_page(GFP_KERNEL);
- if (!page)
+ buffer = kzalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!buffer)
return -ENOMEM;
local_irq_save(flags);
if (tty_port_initialized(port)) {
- free_page(page);
+ kfree(buffer);
goto errout;
}
if (info->xmit.buf)
- free_page(page);
+ kfree(buffer);
else
- info->xmit.buf = (unsigned char *) page;
+ info->xmit.buf = buffer;
#ifdef SERIAL_DEBUG_OPEN
printk("starting up ttys%d ...", info->line);
@@ -537,7 +537,7 @@ static void rs_shutdown(struct tty_struct *tty, struct serial_state *info)
*/
free_irq(IRQ_AMIGA_VERTB, info);
- free_page((unsigned long)info->xmit.buf);
+ kfree(info->xmit.buf);
info->xmit.buf = NULL;
info->IER = 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/4] tty: serial: men_z135_uart: replace __get_free_page() with kmalloc()
2026-05-28 10:24 [PATCH 0/4] tty: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
2026-05-28 10:24 ` [PATCH 1/4] serial: pch: replace __get_free_page() " Mike Rapoport (Microsoft)
2026-05-28 10:24 ` [PATCH 2/4] tty: amiserial: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
@ 2026-05-28 10:24 ` Mike Rapoport (Microsoft)
2026-05-29 7:47 ` Jiri Slaby
2026-05-28 10:24 ` [PATCH 4/4] vc_screen: replace __get_free_pages() " Mike Rapoport (Microsoft)
3 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 10:24 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Mike Rapoport, linux-kernel, linux-mm, linux-serial
men_z135_probe() allocates a receive staging buffer filled by the
CPU via memcpy_fromio() from the device MMIO region.
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.
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
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/tty/serial/men_z135_uart.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c
index 6fad57fee912..9c32b01edc9e 100644
--- a/drivers/tty/serial/men_z135_uart.c
+++ b/drivers/tty/serial/men_z135_uart.c
@@ -17,6 +17,7 @@
#include <linux/bitops.h>
#include <linux/mcb.h>
+#include <linux/slab.h>
#define MEN_Z135_MAX_PORTS 12
#define MEN_Z135_BASECLK 29491200
#define MEN_Z135_FIFO_SIZE 1024
@@ -811,7 +812,7 @@ static int men_z135_probe(struct mcb_device *mdev,
if (!uart)
return -ENOMEM;
- uart->rxbuf = (unsigned char *)__get_free_page(GFP_KERNEL);
+ uart->rxbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!uart->rxbuf)
return -ENOMEM;
@@ -841,7 +842,7 @@ static int men_z135_probe(struct mcb_device *mdev,
return 0;
err:
- free_page((unsigned long) uart->rxbuf);
+ kfree(uart->rxbuf);
dev_err(dev, "Failed to add UART: %d\n", err);
return err;
@@ -858,7 +859,7 @@ static void men_z135_remove(struct mcb_device *mdev)
line--;
uart_remove_one_port(&men_z135_driver, &uart->port);
- free_page((unsigned long) uart->rxbuf);
+ kfree(uart->rxbuf);
}
static const struct mcb_device_id men_z135_ids[] = {
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 3/4] tty: serial: men_z135_uart: replace __get_free_page() with kmalloc()
2026-05-28 10:24 ` [PATCH 3/4] tty: serial: men_z135_uart: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
@ 2026-05-29 7:47 ` Jiri Slaby
2026-05-29 8:43 ` Mike Rapoport
0 siblings, 1 reply; 9+ messages in thread
From: Jiri Slaby @ 2026-05-29 7:47 UTC (permalink / raw)
To: Mike Rapoport (Microsoft), Greg Kroah-Hartman
Cc: linux-kernel, linux-mm, linux-serial
On 28. 05. 26, 12:24, Mike Rapoport (Microsoft) wrote:
> men_z135_probe() allocates a receive staging buffer filled by the
> CPU via memcpy_fromio() from the device MMIO region.
>
> 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.
>
> 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
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/tty/serial/men_z135_uart.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c
> index 6fad57fee912..9c32b01edc9e 100644
> --- a/drivers/tty/serial/men_z135_uart.c
> +++ b/drivers/tty/serial/men_z135_uart.c
> @@ -17,6 +17,7 @@
> #include <linux/bitops.h>
> #include <linux/mcb.h>
>
> +#include <linux/slab.h>
> #define MEN_Z135_MAX_PORTS 12
This one is misplaced.
thanks,
--
js
suse labs
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] tty: serial: men_z135_uart: replace __get_free_page() with kmalloc()
2026-05-29 7:47 ` Jiri Slaby
@ 2026-05-29 8:43 ` Mike Rapoport
2026-05-29 8:52 ` Jiri Slaby
0 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2026-05-29 8:43 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Greg Kroah-Hartman, linux-kernel, linux-mm, linux-serial
On Fri, May 29, 2026 at 09:47:33AM +0200, Jiri Slaby wrote:
> On 28. 05. 26, 12:24, Mike Rapoport (Microsoft) wrote:
> > men_z135_probe() allocates a receive staging buffer filled by the
> > CPU via memcpy_fromio() from the device MMIO region.
> >
> > 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.
> >
> > 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
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> > drivers/tty/serial/men_z135_uart.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c
> > index 6fad57fee912..9c32b01edc9e 100644
> > --- a/drivers/tty/serial/men_z135_uart.c
> > +++ b/drivers/tty/serial/men_z135_uart.c
> > @@ -17,6 +17,7 @@
> > #include <linux/bitops.h>
> > #include <linux/mcb.h>
> > +#include <linux/slab.h>
> > #define MEN_Z135_MAX_PORTS 12
>
> This one is misplaced.
Do you mean an empty line is missing? Or there's particular order of
includes here?
> thanks,
> --
> js
> suse labs
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] tty: serial: men_z135_uart: replace __get_free_page() with kmalloc()
2026-05-29 8:43 ` Mike Rapoport
@ 2026-05-29 8:52 ` Jiri Slaby
0 siblings, 0 replies; 9+ messages in thread
From: Jiri Slaby @ 2026-05-29 8:52 UTC (permalink / raw)
To: Mike Rapoport; +Cc: Greg Kroah-Hartman, linux-kernel, linux-mm, linux-serial
On 29. 05. 26, 10:43, Mike Rapoport wrote:
> On Fri, May 29, 2026 at 09:47:33AM +0200, Jiri Slaby wrote:
>> On 28. 05. 26, 12:24, Mike Rapoport (Microsoft) wrote:
>>> men_z135_probe() allocates a receive staging buffer filled by the
>>> CPU via memcpy_fromio() from the device MMIO region.
>>>
>>> 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.
>>>
>>> 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
>>> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
>>> ---
>>> drivers/tty/serial/men_z135_uart.c | 7 ++++---
>>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c
>>> index 6fad57fee912..9c32b01edc9e 100644
>>> --- a/drivers/tty/serial/men_z135_uart.c
>>> +++ b/drivers/tty/serial/men_z135_uart.c
>>> @@ -17,6 +17,7 @@
>>> #include <linux/bitops.h>
>>> #include <linux/mcb.h>
>>> +#include <linux/slab.h>
>>> #define MEN_Z135_MAX_PORTS 12
>>
>> This one is misplaced.
>
> Do you mean an empty line is missing? Or there's particular order of
> includes here?
You added it after an empty line -- along to #defines. You should had
added it along #includes instead -- before the empty line.
>> thanks,
>> --
>> js
>> suse labs
>
--
js
suse labs
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/4] vc_screen: replace __get_free_pages() with kmalloc()
2026-05-28 10:24 [PATCH 0/4] tty: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
` (2 preceding siblings ...)
2026-05-28 10:24 ` [PATCH 3/4] tty: serial: men_z135_uart: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
@ 2026-05-28 10:24 ` Mike Rapoport (Microsoft)
2026-05-29 7:47 ` Jiri Slaby
3 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-05-28 10:24 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Mike Rapoport, linux-kernel, linux-mm, linux-serial
vcs_read() and vcs_write() allocate staging buffers with
__get_free_pages().
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 it's a
modern way of saying "I need a page-sized buffer"
Replace use of __get_free_page() with kmalloc() and drop unused now
DEFINE_FREE(free_page_ptr ...)
Link: https://lore.kernel.org/all/700c5a5f-3128-4671-99aa-827ca73f5cdf@kernel.org
Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/tty/vt/vc_screen.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index 4d2d46c95fef..386c80efc672 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -53,8 +53,6 @@
#define HEADER_SIZE 4u
#define CON_BUF_SIZE (IS_ENABLED(CONFIG_BASE_SMALL) ? 256 : PAGE_SIZE)
-DEFINE_FREE(free_page_ptr, void *, if (_T) free_page((unsigned long)_T));
-
/*
* Our minor space:
*
@@ -371,7 +369,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
loff_t pos;
bool viewed, attr, uni_mode;
- char *con_buf __free(free_page_ptr) = (char *)__get_free_page(GFP_KERNEL);
+ char *con_buf __free(kfree) = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!con_buf)
return -ENOMEM;
@@ -596,7 +594,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
if (use_unicode(inode))
return -EOPNOTSUPP;
- char *con_buf __free(free_page_ptr) = (char *)__get_free_page(GFP_KERNEL);
+ char *con_buf __free(kfree) = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!con_buf)
return -ENOMEM;
--
2.53.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 4/4] vc_screen: replace __get_free_pages() with kmalloc()
2026-05-28 10:24 ` [PATCH 4/4] vc_screen: replace __get_free_pages() " Mike Rapoport (Microsoft)
@ 2026-05-29 7:47 ` Jiri Slaby
0 siblings, 0 replies; 9+ messages in thread
From: Jiri Slaby @ 2026-05-29 7:47 UTC (permalink / raw)
To: Mike Rapoport (Microsoft), Greg Kroah-Hartman
Cc: linux-kernel, linux-mm, linux-serial
On 28. 05. 26, 12:24, Mike Rapoport (Microsoft) wrote:
> vcs_read() and vcs_write() allocate staging buffers with
> __get_free_pages().
>
> 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 it's a
> modern way of saying "I need a page-sized buffer"
>
> Replace use of __get_free_page() with kmalloc() and drop unused now
> DEFINE_FREE(free_page_ptr ...)
>
> Link: https://lore.kernel.org/all/700c5a5f-3128-4671-99aa-827ca73f5cdf@kernel.org
> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> drivers/tty/vt/vc_screen.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
> index 4d2d46c95fef..386c80efc672 100644
> --- a/drivers/tty/vt/vc_screen.c
> +++ b/drivers/tty/vt/vc_screen.c
> @@ -53,8 +53,6 @@
> #define HEADER_SIZE 4u
> #define CON_BUF_SIZE (IS_ENABLED(CONFIG_BASE_SMALL) ? 256 : PAGE_SIZE)
>
> -DEFINE_FREE(free_page_ptr, void *, if (_T) free_page((unsigned long)_T));
> -
Indeed, I don't know why I came up with this in the first place :P.
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
> @@ -371,7 +369,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
> loff_t pos;
> bool viewed, attr, uni_mode;
>
> - char *con_buf __free(free_page_ptr) = (char *)__get_free_page(GFP_KERNEL);
> + char *con_buf __free(kfree) = kmalloc(PAGE_SIZE, GFP_KERNEL);
> if (!con_buf)
> return -ENOMEM;
>
> @@ -596,7 +594,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
> if (use_unicode(inode))
> return -EOPNOTSUPP;
>
> - char *con_buf __free(free_page_ptr) = (char *)__get_free_page(GFP_KERNEL);
> + char *con_buf __free(kfree) = kmalloc(PAGE_SIZE, GFP_KERNEL);
> if (!con_buf)
> return -ENOMEM;
>
>
--
js
suse labs
^ permalink raw reply [flat|nested] 9+ messages in thread