Re: [PATCH v2 01/19] ARM: i.MX: boot: Coalesce copy-pasted code

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

 



On Mon, Apr 16, 2018 at 11:58 PM, Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> wrote:
> On Mon, Apr 16, 2018 at 12:31:39PM -0700, Andrey Smirnov wrote:
>> All of the instances of imx*_boot_save_loc() do exactly the same thing with
>> the only difference being SoC-specific imx*_get_boot_source
>> call. Convert the code into a generic function taking function pointer
>> + a macro to take care of the boilerplate.
>>
>> Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
>> ---
>>  arch/arm/mach-imx/boot.c | 85 ++++++++++--------------------------------------
>>  1 file changed, 17 insertions(+), 68 deletions(-)
>>
>> +imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
>>  {
>>       enum bootsource src = BOOTSOURCE_UNKNOWN;
>>       int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
>>
>> -     imx7_get_boot_source(&src, &instance);
>> +     get_boot_source(&src, &instance);
>>
>>       bootsource_set(src);
>>       bootsource_set_instance(instance);
>>  }
>> +
>> +#define IMX_BOOT_SAVE_LOC(soc)                                       \
>> +     void soc##_boot_save_loc(void)                          \
>> +     {                                                       \
>> +             imx_boot_save_loc(soc##_get_boot_source);       \
>> +     }
>> +
>> +IMX_BOOT_SAVE_LOC(imx25)
>> +IMX_BOOT_SAVE_LOC(imx27)
>> +IMX_BOOT_SAVE_LOC(imx35)
>> +IMX_BOOT_SAVE_LOC(imx51)
>> +IMX_BOOT_SAVE_LOC(imx53)
>> +IMX_BOOT_SAVE_LOC(imx6)
>> +IMX_BOOT_SAVE_LOC(imx7)
>
> I do not really like this patch. Yes, it saves a few lines of code, but
> with the cost of making it less readable.
>

Can you elaborate on what part is less readable? IMHO, replacing 68
line of mostly copy pasted code with 17 of a generic function is a bit
more than "saving a few lines of code", so I think it's worth trying
to find a solution that would be acceptable from both perspectives:
conciseness and readability.

Would replacing function pointer with a switch (imx_cpu_type) and
expanding IMX_BOOT_SAVE_LOC() make this patch readable enough to be
accepted?

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux