mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "bhe@redhat.com" <bhe@redhat.com>
To: David Binderman <dcb314@hotmail.com>
Cc: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"kexec@lists.infradead.org" <kexec@lists.infradead.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: linux-6.19-rc4/kernel/kexec_core.c:425: Possible loss of data ?
Date: Thu, 8 Jan 2026 11:12:46 +0800	[thread overview]
Message-ID: <aV8grrXoMlkJZ0fY@MiWiFi-R3L-srv> (raw)
In-Reply-To: <VI1PR02MB395224C3D5F37DEDA794AED09C84A@VI1PR02MB3952.eurprd02.prod.outlook.com>

On 01/07/26 at 02:32pm, David Binderman wrote:
> Hello there,
> 
> Static analyser cppcheck says:
> 
> linux-6.19-rc4/kernel/kexec_core.c:425:7: style: int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information. [truncLongCastAssignment]
> 
> Source code is
> 
>     size = (1 << order) << PAGE_SHIFT;
> 
> I have no idea how large order gets, but if it gets over about
> 30 or so, then IMHO there will be a loss of bits.

We may not need to worry about it. In all places where
kimage_alloc_control_pages is called, the order is 0 or
get_order(KEXEC_CONTROL_PAGE_SIZE) on mips which is 2. 

arch/mips/include/asm/kexec.h:#define KEXEC_CONTROL_PAGE_SIZE (4096 + 3*4096)

[~]$ git grep kimage_alloc_control_pages
arch/arm64/kernel/machine_kexec.c:      struct page *page = kimage_alloc_control_pages(kimage, 0);
arch/x86/kernel/machine_kexec_64.c:     page = kimage_alloc_control_pages(image, 0);
include/linux/kexec.h:extern struct page *kimage_alloc_control_pages(struct kimage *image,
kernel/crash_core.c:    vmcoreinfo_page = kimage_alloc_control_pages(image, 0);
kernel/kexec.c: image->control_code_page = kimage_alloc_control_pages(image,
kernel/kexec.c:         image->swap_page = kimage_alloc_control_pages(image, 0);
kernel/kexec_core.c:struct page *kimage_alloc_control_pages(struct kimage *image,
kernel/kexec_file.c:    image->control_code_page = kimage_alloc_control_pages(image,
kernel/kexec_file.c:            image->swap_page = kimage_alloc_control_pages(image, 0);

> 
> Perhaps some sanity check on the value of order would
> be a good idea ? Either that or
> 
>     size = (1UL << order) << PAGE_SHIFT;
> 
> might be better code.

That is fine if people is worried, a patch is welcome.


  reply	other threads:[~2026-01-08  3:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-07 14:32 David Binderman
2026-01-08  3:12 ` bhe [this message]
2026-01-08  8:42   ` David Binderman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aV8grrXoMlkJZ0fY@MiWiFi-R3L-srv \
    --to=bhe@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dcb314@hotmail.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®