platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth()
PATCH 1/2 platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth()
All callers of tlmi_create_auth() also call kobject_init(&pwd_setting->kobj, &tlmi_pwd_setting_ktype) on the returned tlmi_pwd_setting struct. Move this into tlmi_create_auth().
--- drivers/platform/x86/think-lmi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/platform/x86/think-lmi.c +3 -8
@@ -1057,6 +1057,9 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type, new_pwd->minlen = tlmi_priv.pwdcfg.core.min_length; new_pwd->maxlen = tlmi_priv.pwdcfg.core.max_length; new_pwd->index =0 ; + +kobject_init (&new_pwd->kobj, &tlmi_pwd_setting_ktype); +return new_pwd; }
@@ -1146,8 +1149,6 @@ static int tlmi_analyze(void)if (tlmi_priv.pwdcfg.core.password_state &TLMI_PAP_PWD ) tlmi_priv.pwd_admin->valid = true; -kobject_init (&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype); - tlmi_priv.pwd_power =tlmi_create_auth ("pop" ,"power-on" );if (!tlmi_priv.pwd_power) { ret = -ENOMEM ;
@@ -1156,8 +1157,6 @@ static int tlmi_analyze(void)if (tlmi_priv.pwdcfg.core.password_state &TLMI_POP_PWD ) tlmi_priv.pwd_power->valid = true; -kobject_init (&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype); -if (tlmi_priv.opcode_support) { tlmi_priv.pwd_system =tlmi_create_auth ("sys" ,"system" );if (!tlmi_priv.pwd_system) {
@@ -1167,21 +1166,17 @@ static int tlmi_analyze(void)if (tlmi_priv.pwdcfg.core.password_state &TLMI_SYS_PWD ) tlmi_priv.pwd_system->valid = true; -kobject_init (&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype); - tlmi_priv.pwd_hdd =tlmi_create_auth ("hdd" ,"hdd" );if (!tlmi_priv.pwd_hdd) { ret = -ENOMEM ; goto fail_clear_attr; } -kobject_init (&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype); tlmi_priv.pwd_nvme =tlmi_create_auth ("nvm" ,"nvme" );if (!tlmi_priv.pwd_nvme) { ret = -ENOMEM ; goto fail_clear_attr; } -kobject_init (&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype);if (tlmi_priv.pwdcfg.core.password_state &TLMI_HDD_PWD ) {/* Check if PWD is configured and set index to first drive found */
Signature · 1 line
2.31.1
PATCH 2/2 platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit
Creating the tlmi_pwd_setting structs can only fail with -ENOMEM, set ret to this once and simplify the error handling a bit.
--- drivers/platform/x86/think-lmi.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/platform/x86/think-lmi.c +11 -15
@@ -1141,42 +1141,38 @@ static int tlmi_analyze(void)if (ret) goto fail_clear_attr; +/* All failures below boil down to kmalloc failures */ + ret = -ENOMEM ; + tlmi_priv.pwd_admin =tlmi_create_auth ("pap" ,"bios-admin" ); -if (!tlmi_priv.pwd_admin) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_admin) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_PAP_PWD ) tlmi_priv.pwd_admin->valid = true; tlmi_priv.pwd_power =tlmi_create_auth ("pop" ,"power-on" ); -if (!tlmi_priv.pwd_power) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_power) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_POP_PWD ) tlmi_priv.pwd_power->valid = true;if (tlmi_priv.opcode_support) { tlmi_priv.pwd_system =tlmi_create_auth ("sys" ,"system" ); -if (!tlmi_priv.pwd_system) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_system) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_SYS_PWD ) tlmi_priv.pwd_system->valid = true; tlmi_priv.pwd_hdd =tlmi_create_auth ("hdd" ,"hdd" ); -if (!tlmi_priv.pwd_hdd) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_hdd) goto fail_clear_attr; - } tlmi_priv.pwd_nvme =tlmi_create_auth ("nvm" ,"nvme" ); -if (!tlmi_priv.pwd_nvme) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_nvme) goto fail_clear_attr; - }if (tlmi_priv.pwdcfg.core.password_state &TLMI_HDD_PWD ) {/* Check if PWD is configured and set index to first drive found */
Signature · 1 line
2.31.1
Re: [External] [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit
Thanks Hans,
Quoted 57 lines · Hans de Goede
Creating the
tlmi_pwd_settingstructs can only fail with-ENOMEM, set ret to this once and simplify the error handling a bit.Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/think-lmi.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)drivers/platform/x86/think-lmi.c +10
-12@@ -1141,42 +1141,38 @@ static int tlmi_analyze(void)if (ret) goto fail_clear_attr; +/* All failures below boil down to kmalloc failures */ + ret = -ENOMEM ; + tlmi_priv.pwd_admin =tlmi_create_auth ("pap" ,"bios-admin" ); -if (!tlmi_priv.pwd_admin) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_admin) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_PAP_PWD ) tlmi_priv.pwd_admin->valid = true; tlmi_priv.pwd_power =tlmi_create_auth ("pop" ,"power-on" ); -if (!tlmi_priv.pwd_power) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_power) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_POP_PWD ) tlmi_priv.pwd_power->valid = true;if (tlmi_priv.opcode_support) { tlmi_priv.pwd_system =tlmi_create_auth ("sys" ,"system" ); -if (!tlmi_priv.pwd_system) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_system) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_SYS_PWD ) tlmi_priv.pwd_system->valid = true; tlmi_priv.pwd_hdd =tlmi_create_auth ("hdd" ,"hdd" ); -if (!tlmi_priv.pwd_hdd) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_hdd) goto fail_clear_attr; - }
drivers/platform/x86/think-lmi.c static int tlmi_analyze(void) · line 1178
Quoted 10 lines
drivers/platform/x86/think-lmi.c +1
-3tlmi_priv.pwd_nvme =tlmi_create_auth ("nvm" ,"nvme" ); -if (!tlmi_priv.pwd_nvme) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_nvme) goto fail_clear_attr; - }if (tlmi_priv.pwdcfg.core.password_state &TLMI_HDD_PWD ) {/* Check if PWD is configured and set index to first drive found */
Looks good, and works well. Verified with modifying NVMe and Admin password on M90n
Re: [External] [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit
Hi,
Quoted 67 lines · Mark Pearson
Thanks Hans,
Quoted 64 lines · Hans de Goede
Creating the
tlmi_pwd_settingstructs can only fail with-ENOMEM, set ret to this once and simplify the error handling a bit.Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/think-lmi.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)drivers/platform/x86/think-lmi.c +11
-15@@ -1141,42 +1141,38 @@ static int tlmi_analyze(void)if (ret) goto fail_clear_attr; +/* All failures below boil down to kmalloc failures */ + ret = -ENOMEM ; + tlmi_priv.pwd_admin =tlmi_create_auth ("pap" ,"bios-admin" ); -if (!tlmi_priv.pwd_admin) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_admin) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_PAP_PWD ) tlmi_priv.pwd_admin->valid = true; tlmi_priv.pwd_power =tlmi_create_auth ("pop" ,"power-on" ); -if (!tlmi_priv.pwd_power) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_power) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_POP_PWD ) tlmi_priv.pwd_power->valid = true;if (tlmi_priv.opcode_support) { tlmi_priv.pwd_system =tlmi_create_auth ("sys" ,"system" ); -if (!tlmi_priv.pwd_system) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_system) goto fail_clear_attr; - } +if (tlmi_priv.pwdcfg.core.password_state &TLMI_SYS_PWD ) tlmi_priv.pwd_system->valid = true; tlmi_priv.pwd_hdd =tlmi_create_auth ("hdd" ,"hdd" ); -if (!tlmi_priv.pwd_hdd) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_hdd) goto fail_clear_attr; - } tlmi_priv.pwd_nvme =tlmi_create_auth ("nvm" ,"nvme" ); -if (!tlmi_priv.pwd_nvme) { - ret = -ENOMEM ; +if (!tlmi_priv.pwd_nvme) goto fail_clear_attr; - }
Quoted 7 lines
drivers/platform/x86/think-lmi.c static int tlmi_analyze(void) · line 1178
Quoted 3 lines
drivers/platform/x86/think-lmi.c +0
-0if (tlmi_priv.pwdcfg.core.password_state &TLMI_HDD_PWD ) {/* Check if PWD is configured and set index to first drive found */ Looks good, and works well. Verified with modifying NVMe and Admin password on M90n
Tested-by Mark Pearson <[email protected]>
Thank you, I've pushed both patches to my for-next branch now, with your Tested-by tag added.
Regards,
Hans
Thanks Hans
Quoted 54 lines · Hans de Goede
All callers of
tlmi_create_auth()also callkobject_init(&pwd_setting->kobj, &tlmi_pwd_setting_ktype)on the returnedtlmi_pwd_settingstruct. Move this intotlmi_create_auth().Signed-off-by Hans de Goede <[email protected]>--- drivers/platform/x86/think-lmi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)drivers/platform/x86/think-lmi.c +3
-7@@ -1057,6 +1057,9 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type, new_pwd->minlen = tlmi_priv.pwdcfg.core.min_length; new_pwd->maxlen = tlmi_priv.pwdcfg.core.max_length; new_pwd->index =0 ; + +kobject_init (&new_pwd->kobj, &tlmi_pwd_setting_ktype); +return new_pwd; }@@ -1146,8 +1149,6 @@ static int tlmi_analyze(void)if (tlmi_priv.pwdcfg.core.password_state &TLMI_PAP_PWD ) tlmi_priv.pwd_admin->valid = true; -kobject_init (&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype); - tlmi_priv.pwd_power =tlmi_create_auth ("pop" ,"power-on" );if (!tlmi_priv.pwd_power) { ret = -ENOMEM ;@@ -1156,8 +1157,6 @@ static int tlmi_analyze(void)if (tlmi_priv.pwdcfg.core.password_state &TLMI_POP_PWD ) tlmi_priv.pwd_power->valid = true; -kobject_init (&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype); -if (tlmi_priv.opcode_support) { tlmi_priv.pwd_system =tlmi_create_auth ("sys" ,"system" );if (!tlmi_priv.pwd_system) {@@ -1167,21 +1166,17 @@ static int tlmi_analyze(void)if (tlmi_priv.pwdcfg.core.password_state &TLMI_SYS_PWD ) tlmi_priv.pwd_system->valid = true; -kobject_init (&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype); - tlmi_priv.pwd_hdd =tlmi_create_auth ("hdd" ,"hdd" );if (!tlmi_priv.pwd_hdd) { ret = -ENOMEM ; goto fail_clear_attr; } -kobject_init (&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype);
drivers/platform/x86/think-lmi.c static int tlmi_analyze(void) · line 1182
Quoted 10 lines
drivers/platform/x86/think-lmi.c +0
-1tlmi_priv.pwd_nvme =tlmi_create_auth ("nvm" ,"nvme" );if (!tlmi_priv.pwd_nvme) { ret = -ENOMEM ; goto fail_clear_attr; } -kobject_init (&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype);if (tlmi_priv.pwdcfg.core.password_state &TLMI_HDD_PWD ) {/* Check if PWD is configured and set index to first drive found */
Looks good, and works well. Verified with modifying NVMe and Admin password on M90n