Re: [PATCH v2 2/4] tty: amiserial: replace get_zeroed_page() with kzalloc()

From: Geert Uytterhoeven

Date: Thu Jul 09 2026 - 04:11:20 EST


On Thu, 9 Jul 2026 at 10:03, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> wrote:
> On Sun, 31 May 2026 at 09:04, Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx> wrote:
> > 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@xxxxxxxxxx
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
>
> Thanks for your patch, which is now commit d26ed502d0c7c05c ("tty:
> amiserial: replace get_zeroed_page() with kzalloc()") in tty/tty-next

Sorry, I replied to the work version: the applied patch is not this
v2, or the even newer v3, but v1?

> > --- 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;
>
> "char *", to match the type of info->xmit.buf?
>
> >
> > - 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);

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds