Skip to content

Commit 36560ef

Browse files
mrhpearsonjwrdegoede
authored andcommitted
platform/x86: think-lmi: certificate support clean ups
Complete some clean-ups as reqested from the last review as follow-ups - Remove certificate from structure as no need to store it any more - Clean up return code handling - Moved freeing of signature to before admin object released (issue seen in testing when unloading module) - Minor code flow improvements Signed-off-by: Mark Pearson <markpearson@lenovo.com> Link: https://lore.kernel.org/r/20220321180624.4761-1-markpearson@lenovo.com Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent 3123109 commit 36560ef

2 files changed

Lines changed: 15 additions & 30 deletions

File tree

drivers/platform/x86/think-lmi.c

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -740,16 +740,8 @@ static ssize_t certificate_store(struct kobject *kobj,
740740
if (!tlmi_priv.certificate_support)
741741
return -EOPNOTSUPP;
742742

743-
new_cert = kstrdup(buf, GFP_KERNEL);
744-
if (!new_cert)
745-
return -ENOMEM;
746-
/* Strip out CR if one is present */
747-
strip_cr(new_cert);
748-
749743
/* If empty then clear installed certificate */
750-
if (new_cert[0] == '\0') { /* Clear installed certificate */
751-
kfree(new_cert);
752-
744+
if ((buf[0] == '\0') || (buf[0] == '\n')) { /* Clear installed certificate */
753745
/* Check that signature is set */
754746
if (!setting->signature || !setting->signature[0])
755747
return -EACCES;
@@ -763,14 +755,16 @@ static ssize_t certificate_store(struct kobject *kobj,
763755

764756
ret = tlmi_simple_call(LENOVO_CLEAR_BIOS_CERT_GUID, auth_str);
765757
kfree(auth_str);
766-
if (ret)
767-
return ret;
768758

769-
kfree(setting->certificate);
770-
setting->certificate = NULL;
771-
return count;
759+
return ret ?: count;
772760
}
773761

762+
new_cert = kstrdup(buf, GFP_KERNEL);
763+
if (!new_cert)
764+
return -ENOMEM;
765+
/* Strip out CR if one is present */
766+
strip_cr(new_cert);
767+
774768
if (setting->cert_installed) {
775769
/* Certificate is installed so this is an update */
776770
if (!setting->signature || !setting->signature[0]) {
@@ -792,21 +786,14 @@ static ssize_t certificate_store(struct kobject *kobj,
792786
auth_str = kasprintf(GFP_KERNEL, "%s,%s",
793787
new_cert, setting->password);
794788
}
795-
if (!auth_str) {
796-
kfree(new_cert);
789+
kfree(new_cert);
790+
if (!auth_str)
797791
return -ENOMEM;
798-
}
799792

800793
ret = tlmi_simple_call(guid, auth_str);
801794
kfree(auth_str);
802-
if (ret) {
803-
kfree(new_cert);
804-
return ret;
805-
}
806795

807-
kfree(setting->certificate);
808-
setting->certificate = new_cert;
809-
return count;
796+
return ret ?: count;
810797
}
811798

812799
static struct kobj_attribute auth_certificate = __ATTR_WO(certificate);
@@ -1194,6 +1181,10 @@ static void tlmi_release_attr(void)
11941181

11951182
kset_unregister(tlmi_priv.attribute_kset);
11961183

1184+
/* Free up any saved signatures */
1185+
kfree(tlmi_priv.pwd_admin->signature);
1186+
kfree(tlmi_priv.pwd_admin->save_signature);
1187+
11971188
/* Authentication structures */
11981189
sysfs_remove_group(&tlmi_priv.pwd_admin->kobj, &auth_attr_group);
11991190
kobject_put(&tlmi_priv.pwd_admin->kobj);
@@ -1210,11 +1201,6 @@ static void tlmi_release_attr(void)
12101201
}
12111202

12121203
kset_unregister(tlmi_priv.authentication_kset);
1213-
1214-
/* Free up any saved certificates/signatures */
1215-
kfree(tlmi_priv.pwd_admin->certificate);
1216-
kfree(tlmi_priv.pwd_admin->signature);
1217-
kfree(tlmi_priv.pwd_admin->save_signature);
12181204
}
12191205

12201206
static int tlmi_sysfs_init(void)

drivers/platform/x86/think-lmi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ struct tlmi_pwd_setting {
6363
int index; /*Used for HDD and NVME auth */
6464
enum level_option level;
6565
bool cert_installed;
66-
char *certificate;
6766
char *signature;
6867
char *save_signature;
6968
};

0 commit comments

Comments
 (0)