[PATCH v4] net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag
Chen Lin
chen45464546 at 163.com
Wed Jun 8 05:43:31 PDT 2022
At 2022-06-08 07:14:13, "Jakub Kicinski" <kuba at kernel.org> wrote:
>On Tue, 7 Jun 2022 07:39:11 +0800 Chen Lin wrote:
>> +static inline void *mtk_max_lro_buf_alloc(gfp_t gfp_mask)
>
>No need for inline, compiler will inline this anyway.
>
>> +{
>> + void *data;
>
>unsigned long data; then you can move the cast from the long line to
>the return statement, saving us from the strange indentation.
>
>> + data = (void *)__get_free_pages(gfp_mask |
>> + __GFP_COMP | __GFP_NOWARN,
>> + get_order(mtk_max_frag_size(MTK_MAX_LRO_RX_LENGTH)));
>> +
>> + return data;
>> +}
I'll do it like below :
+static void *mtk_max_lro_buf_alloc(gfp_t gfp_mask)
+{
+ unsigned long data;
+ unsigned int size = mtk_max_frag_size(MTK_MAX_LRO_RX_LENGTH);
+
+ data = __get_free_pages(gfp_mask | __GFP_COMP | __GFP_NOWARN,
+ get_order(size));
+
+ return (void *)data;
+}
Through analysis of the ASM code from objdump, I confirmed that
the inline is not necessary. Thanks for your tips.
Also, I confirmed that create a new local variable 'size'
will not affect the generation of a constant 'order' parameter at compile time.
ASM code of calling 'mtk_max_lro_buf_alloc':
'mtk_max_lro_buf_alloc' inlined and 'order'(w1) is a constant 0x2
0000000000004530 <mtk_napi_rx>:
...
4a98: 52854400 mov w0, #0x2a20 // #10784
4a9c: 52800041 mov w1, #0x2 // #2
4aa0: 72a00080 movk w0, #0x4, lsl #16
4aa4: 94000000 bl 0 <__get_free_pages>
4aa8: f90033e0 str x0, [sp, #96]
0000000000000730 <mtk_rx_alloc>:
...
7fc: 2a1703e0 mov w0, w23
800: 52800041 mov w1, #0x2 // #2
804: 7140047f cmp w3, #0x1, lsl #12
808: 54fffe49 b.ls 7d0 <mtk_rx_alloc+0xa0> // b.plast
80c: 94000000 bl 0 <__get_free_pages>
The compiler is smart.
More information about the linux-arm-kernel
mailing list