Re: [PATCH v5 4/4] printk: Give error on attempt to set log buffer length to over 4G

From: Sergey Senozhatsky
Date: Wed Oct 10 2018 - 04:21:38 EST


On (10/10/18 10:09), Petr Mladek wrote:
> > > +#define LOG_BUF_LEN_MAX (u32)(1 << 31)
> > [..]
> > > + if (size > (u64)LOG_BUF_LEN_MAX) {
> > > + size = (u64)LOG_BUF_LEN_MAX;
> > > + pr_err("log_buf over 2G is not supported.\n");
> > > + }
> >
> > Why not INT_MAX?
>
> INT_MAX is 0x7fffffff but we need 0x80000000. I did not find
> any predefined macro.

Hmm, OK. I need to think about it more.

> > > + pr_info("log_buf_len: %u bytes\n", log_buf_len);
> > > + pr_info("early log buf free: %u(%u%%)\n",
> > > free, (free * 100) / __LOG_BUF_LEN);
> >
> > Can 'free * 100' overflow?
>
> Good question. It uses the size of the static buffer. If I count
> correctly then we are on the safe side because LOG_BUF_SHIFT
> is limited by
>
> range 12 25

I didn't know there was Kconfig "range" :)

$ echo $(((1<<25)*100))
3355443200

-ss