Re: [PATCH v2 01/12] md/raid5: Factor out ahead_of_reshape() function

From: Logan Gunthorpe
Date: Thu Apr 28 2022 - 11:45:05 EST

On 2022-04-27 19:49, Guoqing Jiang wrote:
> On 4/28/22 12:07 AM, Logan Gunthorpe wrote:
>> On 2022-04-26 19:28, Guoqing Jiang wrote:
>>>>    +static bool ahead_of_reshape(struct mddev *mddev, sector_t sector,
>>>> +                 sector_t reshape_sector)
>>>> +{
>>>> +    if (mddev->reshape_backwards)
>>>> +        return sector < reshape_sector;
>>>> +    else
>>>> +        return sector >= reshape_sector;
>>>> +}
>>> I think it can be an inline function.
>> Marking static functions in C files as inline is not recommended. GCC
>> will inline it, if it is appropriate.
> Thanks for the link, then I suppose those can be deleted

> linux> grep "static inline" drivers/md/md.h -r

It's standard practice to annotate small functions in headers with
"static inline". Without the inline annotation, any C file that includes
the header and doesn't use the function will emit a "defined but not
used warning".

Functions in headers also should, by definition, be small and
specifically inline-able (ie they are used as a type-safe macro).

static functions in C files (not headers) should not have the inline
keyword as GCC can optimize them and inline them as it sees fit and the
inline keyword doesn't actually do anything.