Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

firewire: ohci: use static function to handle endian issue on PowerPC platform

It is preferable to use static function instead of functional macro in
some points. It checks type of argument, but would be optimized to
embedded code instead of function calls.

This commit obsoletes the functional macro with the static function.
Additionally this commit refactors quirk detection to ease the later work.

Link: https://lore.kernel.org/r/20240702222034.1378764-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

+27 -12
+27 -12
drivers/firewire/ohci.c
··· 875 875 } 876 876 877 877 #if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32) 878 - #define cond_le32_to_cpu(v) \ 879 - (ohci->quirks & QUIRK_BE_HEADERS ? be32_to_cpu(v) : le32_to_cpu(v)) 878 + static u32 cond_le32_to_cpu(__le32 value, bool has_be_header_quirk) 879 + { 880 + return has_be_header_quirk ? be32_to_cpu(value) : le32_to_cpu(value); 881 + } 882 + 883 + static bool has_be_header_quirk(const struct fw_ohci *ohci) 884 + { 885 + return !!(ohci->quirks & QUIRK_BE_HEADERS); 886 + } 880 887 #else 881 - #define cond_le32_to_cpu(v) le32_to_cpu(v) 888 + static u32 cond_le32_to_cpu(__le32 value, bool has_be_header_quirk __maybe_unused) 889 + { 890 + return le32_to_cpu(value); 891 + } 892 + 893 + static bool has_be_header_quirk(const struct fw_ohci *ohci) 894 + { 895 + return false; 896 + } 882 897 #endif 883 898 884 899 static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer) ··· 903 888 u32 status, length, tcode; 904 889 int evt; 905 890 906 - p.header[0] = cond_le32_to_cpu(buffer[0]); 907 - p.header[1] = cond_le32_to_cpu(buffer[1]); 908 - p.header[2] = cond_le32_to_cpu(buffer[2]); 891 + p.header[0] = cond_le32_to_cpu(buffer[0], has_be_header_quirk(ohci)); 892 + p.header[1] = cond_le32_to_cpu(buffer[1], has_be_header_quirk(ohci)); 893 + p.header[2] = cond_le32_to_cpu(buffer[2], has_be_header_quirk(ohci)); 909 894 910 895 tcode = async_header_get_tcode(p.header); 911 896 switch (tcode) { ··· 917 902 break; 918 903 919 904 case TCODE_READ_BLOCK_REQUEST : 920 - p.header[3] = cond_le32_to_cpu(buffer[3]); 905 + p.header[3] = cond_le32_to_cpu(buffer[3], has_be_header_quirk(ohci)); 921 906 p.header_length = 16; 922 907 p.payload_length = 0; 923 908 break; ··· 926 911 case TCODE_READ_BLOCK_RESPONSE: 927 912 case TCODE_LOCK_REQUEST: 928 913 case TCODE_LOCK_RESPONSE: 929 - p.header[3] = cond_le32_to_cpu(buffer[3]); 914 + p.header[3] = cond_le32_to_cpu(buffer[3], has_be_header_quirk(ohci)); 930 915 p.header_length = 16; 931 916 p.payload_length = async_header_get_data_length(p.header); 932 917 if (p.payload_length > MAX_ASYNC_PAYLOAD) { ··· 951 936 952 937 /* FIXME: What to do about evt_* errors? */ 953 938 length = (p.header_length + p.payload_length + 3) / 4; 954 - status = cond_le32_to_cpu(buffer[length]); 939 + status = cond_le32_to_cpu(buffer[length], has_be_header_quirk(ohci)); 955 940 evt = (status >> 16) & 0x1f; 956 941 957 942 p.ack = evt - 16; ··· 2045 2030 return; 2046 2031 } 2047 2032 2048 - generation = (cond_le32_to_cpu(ohci->self_id[0]) >> 16) & 0xff; 2033 + generation = (cond_le32_to_cpu(ohci->self_id[0], has_be_header_quirk(ohci)) >> 16) & 0xff; 2049 2034 rmb(); 2050 2035 2051 2036 for (i = 1, j = 0; j < self_id_count; i += 2, j++) { 2052 - u32 id = cond_le32_to_cpu(ohci->self_id[i]); 2053 - u32 id2 = cond_le32_to_cpu(ohci->self_id[i + 1]); 2037 + u32 id = cond_le32_to_cpu(ohci->self_id[i], has_be_header_quirk(ohci)); 2038 + u32 id2 = cond_le32_to_cpu(ohci->self_id[i + 1], has_be_header_quirk(ohci)); 2054 2039 2055 2040 if (id != ~id2) { 2056 2041 /*