On 26/06/23 09:24PM, Shivang Upadhyay wrote:
> On Tue, 2026-06-23 at 19:49 +0530, Aditya Gupta wrote:
> > +static const char *pnv_get_machine_type(enum PnvChipType chip_type)
> > +{
> > +    if (chip_type == PNV_CHIP_POWER8) {
> > +        return "powernv8";
> > +    } else if (chip_type == PNV_CHIP_POWER9) {
> > +        return "powernv9";
> > +    } else if (chip_type == PNV_CHIP_POWER10) {
> > +        return "powernv10";
> > +    } else if (chip_type == PNV_CHIP_POWER11) {
> > +        return "powernv11";
> > +    } else {
> > +        g_assert_not_reached();
> > +    }
> > +}
> 
> How about refactoring to the following?
> 
>     static const char *const machine_types[] = {
>         [PNV_CHIP_POWER8]  = "powernv8",
>         [PNV_CHIP_POWER9]  = "powernv9",
>         [PNV_CHIP_POWER10] = "powernv10",
>         [PNV_CHIP_POWER11] = "powernv11",
>     };
>     return machine_types[x];

Has a subtle difference, that it may not assert/segfault on unknown
value for x, I want the test to crash/fail if this is called with an
unknown/new processor chip. I believe the if-else/switch is better as it
handles (by 'crashing') unknown values too.

- Aditya G

> 
> ~Shivang.

Reply via email to