s390/cpacf: Make use of invalid opcode produce a link error
authorHarald Freudenberger <freude@linux.ibm.com>
Tue, 14 May 2024 08:09:32 +0000 (10:09 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Thu, 16 May 2024 08:17:11 +0000 (10:17 +0200)
Instead of calling BUG() at runtime introduce and use a prototype for a
non-existing function to produce a link error during compile when a not
supported opcode is used with the __cpacf_query() or __cpacf_check_opcode()
inline functions.

Suggested-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Reviewed-by: Holger Dengler <dengler@linux.ibm.com>
Reviewed-by: Juergen Christ <jchrist@linux.ibm.com>
Cc: stable@vger.kernel.org
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/include/asm/cpacf.h

index 153dc4fcc40a9e5a4fb1c8c5d2023b165a1d2f9b..c786538e397c0810cdd89eb8bc382c9be2249cd6 100644 (file)
 
 typedef struct { unsigned char bytes[16]; } cpacf_mask_t;
 
+/*
+ * Prototype for a not existing function to produce a link
+ * error if __cpacf_query() or __cpacf_check_opcode() is used
+ * with an invalid compile time const opcode.
+ */
+void __cpacf_bad_opcode(void);
+
 static __always_inline void __cpacf_query_rre(u32 opc, u8 r1, u8 r2,
                                              cpacf_mask_t *mask)
 {
@@ -237,7 +244,7 @@ static __always_inline void __cpacf_query(unsigned int opcode,
                __cpacf_query_rre(CPACF_PRNO, 2, 4, mask);
                break;
        default:
-               BUG();
+               __cpacf_bad_opcode();
        }
 }
 
@@ -262,7 +269,8 @@ static __always_inline int __cpacf_check_opcode(unsigned int opcode)
        case CPACF_KMA:
                return test_facility(146);      /* check for MSA8 */
        default:
-               BUG();
+               __cpacf_bad_opcode();
+               return 0;
        }
 }