grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to detect the amount of RAM on non-EFI platforms?


From: Vladimir 'phcoder' Serbinenko
Subject: Re: How to detect the amount of RAM on non-EFI platforms?
Date: Fri, 14 Jul 2023 16:01:52 +0200



Le jeu. 13 juil. 2023, 20:39, Daniel Kiper <dkiper@net-space.pl> a écrit :
On Tue, Jul 11, 2023 at 09:37:15PM +0800, Cyan Yang via Grub-devel wrote:
> Hi again,
>
> On 2023/7/11 10:08, Cyan via Grub-devel wrote:
>
> > static int
> > traverse_mmap_hook (grub_uint64_t addr, grub_uint64_t size, grub_memory_type_t type,
> >                     void *data __attribute__ ((unused)))
> > {
> >   total_mem_bytes += size;
> > }
>
> I discovered a huge problem in my hook function: missing a return at the end of the hook function.
> Without this return the hook function will execute only once.
> And, regions with type GRUB_MEMORY_RESERVED should be skipped. So the hook function body should look like this:
>
> if (type != GRUB_MEMORY_RESERVED) {
>   total_mem_bytes += size;
> }
> return GRUB_ERR_NONE;

You are mixing enum and int types. The function should return 0 here.
That actually makes an interesting point. I think we will need an enum type for hook returns with 2 values: GRUB_HOOK_CONTINUE and GRUB_HOOK_STOP but obviously it's outside of scope of your patch

Anyway, I think it would be nice if you could upstream this module.
Potentially other people may find it useful.

Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]