From d91e728e3c3b72e56ee48c60ebe99464bf8d8df6 Mon Sep 17 00:00:00 2001 From: Ingo Franzki Date: Mon, 18 Nov 2019 12:45:34 +0100 Subject: [PATCH] zkey: Generalize the adapter serial number handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Different crypto card types use different serial number formats. Generalize the handling of serial numbers so that the majority of the code does not have to care about the card type when dealing with it. Signed-off-by: Ingo Franzki Reviewed-by: Harald Freudenberger Signed-off-by: Jan Höppner --- zkey/cca.c | 2 +- zkey/utils.c | 9 +++++---- zkey/utils.h | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/zkey/cca.c b/zkey/cca.c index f8c2c670..411a276c 100644 --- a/zkey/cca.c +++ b/zkey/cca.c @@ -558,7 +558,7 @@ int select_cca_adapter(struct cca_lib *cca, int card, int domain, bool verbose) { unsigned int adapters, adapter; char adapter_serialnr[9]; - char apqn_serialnr[9]; + char apqn_serialnr[SERIALNR_LENGTH]; char temp[10]; int rc, found = 0; diff --git a/zkey/utils.c b/zkey/utils.c index 4abc312b..f0050f28 100644 --- a/zkey/utils.c +++ b/zkey/utils.c @@ -224,10 +224,10 @@ out: } /** - * Gets the 8 character ASCII serial number string of an card from the sysfs. + * Gets the 8-16 character ASCII serial number string of an card from the sysfs. * * @param[in] card card number - * @param[out] serialnr Result buffer + * @param[out] serialnr Result buffer. Must be at least SERIALNR_LENGTH long. * @param[in] verbose if true, verbose messages are printed * * @returns 0 if the serial number was returned. -ENODEV if the APQN is not @@ -235,7 +235,7 @@ out: * -ENOTSUP if the serialnr sysfs attribute is not available, because * the zcrypt kernel module is on an older level. */ -int sysfs_get_serialnr(int card, char serialnr[9], bool verbose) +int sysfs_get_serialnr(int card, char *serialnr, bool verbose) { char *dev_path; int rc = 0; @@ -251,7 +251,8 @@ int sysfs_get_serialnr(int card, char serialnr[9], bool verbose) rc = -ENODEV; goto out; } - if (util_file_read_line(serialnr, 9, "%s/serialnr", dev_path) != 0) { + if (util_file_read_line(serialnr, SERIALNR_LENGTH, "%s/serialnr", + dev_path) != 0) { rc = -ENOTSUP; goto out; } diff --git a/zkey/utils.h b/zkey/utils.h index f361b21d..87bb104f 100644 --- a/zkey/utils.h +++ b/zkey/utils.h @@ -24,7 +24,9 @@ int sysfs_get_card_level(int card); enum card_type sysfs_get_card_type(int card); -int sysfs_get_serialnr(int card, char serialnr[9], bool verbose); +#define SERIALNR_LENGTH 17 + +int sysfs_get_serialnr(int card, char *serialnr, bool verbose); struct fw_version { unsigned int major;