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

From: Guoqing Jiang
Date: Thu Apr 28 2022 - 20:25:48 EST




On 4/28/22 11:44 PM, Logan Gunthorpe wrote:


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.

https://yarchive.net/comp/linux/inline.html
https://www.kernel.org/doc/local/inline.html
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.

I am happy to be taught, but still I can see lots of static function in C files
as well, at least

linux> grep "static inline" drivers/md/*.c -r|wc
     98     661    8630

Anyway, I don't want to argue about it anymore.

Thanks,
Guoqing