Skip to content

Commit

Permalink
s390/cpacf: Make use of invalid opcode produce a link error
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Harald Freudenberger <[email protected]>
Reviewed-by: Holger Dengler <[email protected]>
Reviewed-by: Juergen Christ <[email protected]>
Cc: [email protected]
Signed-off-by: Heiko Carstens <[email protected]>
  • Loading branch information
hfreude authored and hcahca committed May 16, 2024
1 parent 830999b commit 32e8bd6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions arch/s390/include/asm/cpacf.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@

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)
{
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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;
}
}

Expand Down

0 comments on commit 32e8bd6

Please sign in to comment.