lkml.org 
[lkml]   [2020]   [Jul]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v3 03/12] powerpc/kexec_file: add helper functions for getting memory ranges
Date


On 15/07/20 5:19 am, Thiago Jung Bauermann wrote:
>

<snip>

> <snip>
>
>> +/**
>> + * get_mem_rngs_size - Get the allocated size of mrngs based on
>> + * max_nr_ranges and chunk size.
>> + * @mrngs: Memory ranges.
>> + *
>> + * Returns the maximum no. of ranges.
>
> This isn't correct. It returns the maximum size of @mrngs.

True. Will update..

> <snip>
>
>> +/**
>> + * add_tce_mem_ranges - Adds tce-table range to the given memory ranges list.
>> + * @mem_ranges: Range list to add the memory range(s) to.
>> + *
>> + * Returns 0 on success, negative errno on error.
>> + */
>> +int add_tce_mem_ranges(struct crash_mem **mem_ranges)
>> +{
>> + struct device_node *dn;
>> + int ret;
>> +
>> + for_each_node_by_type(dn, "pci") {
>> + u64 base;
>> + u32 size;
>> +
>> + ret = of_property_read_u64(dn, "linux,tce-base", &base);
>> + ret |= of_property_read_u32(dn, "linux,tce-size", &size);
>> + if (!ret)
>
> Shouldn't the condition be `ret` instead of `!ret`?

Oops! Will fix it.

>> +/**
>> + * sort_memory_ranges - Sorts the given memory ranges list.
>> + * @mem_ranges: Range list to sort.
>> + * @merge: If true, merge the list after sorting.
>> + *
>> + * Returns nothing.
>> + */
>> +void sort_memory_ranges(struct crash_mem *mrngs, bool merge)
>> +{
>> + struct crash_mem_range *rngs;
>> + struct crash_mem_range rng;
>> + int i, j, idx;
>> +
>> + if (!mrngs)
>> + return;
>> +
>> + /* Sort the ranges in-place */
>> + rngs = &mrngs->ranges[0];
>> + for (i = 0; i < mrngs->nr_ranges; i++) {
>> + idx = i;
>> + for (j = (i + 1); j < mrngs->nr_ranges; j++) {
>> + if (rngs[idx].start > rngs[j].start)
>> + idx = j;
>> + }
>> + if (idx != i) {
>> + rng = rngs[idx];
>> + rngs[idx] = rngs[i];
>> + rngs[i] = rng;
>> + }
>> + }
>
> Would it work using sort() from lib/sort.c here?

Yeah. I think we could reuse it with a simple compare callback. Will do that.

Thanks
Hari

\
 
 \ /
  Last update: 2020-07-16 23:09    [W:0.234 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site