All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth()
@ 2021-11-18 11:41 Hans de Goede
  2021-11-18 11:41 ` [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit Hans de Goede
  2021-11-18 15:45 ` [External] [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth() Mark Pearson
  0 siblings, 2 replies; 5+ messages in thread
From: Hans de Goede @ 2021-11-18 11:41 UTC (permalink / raw)
  To: Mark Gross, Andy Shevchenko, Mark Pearson
  Cc: Hans de Goede, platform-driver-x86

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().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/think-lmi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index fee9e004161f..6eba69334fa6 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -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 */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit
  2021-11-18 11:41 [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth() Hans de Goede
@ 2021-11-18 11:41 ` Hans de Goede
  2021-11-18 15:46   ` [External] " Mark Pearson
  2021-11-18 15:45 ` [External] [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth() Mark Pearson
  1 sibling, 1 reply; 5+ messages in thread
From: Hans de Goede @ 2021-11-18 11:41 UTC (permalink / raw)
  To: Mark Gross, Andy Shevchenko, Mark Pearson
  Cc: Hans de Goede, platform-driver-x86

Creating the tlmi_pwd_setting structs can only fail with -ENOMEM, set
ret to this once and simplify the error handling a bit.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/think-lmi.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 6eba69334fa6..27ab8e4e5b83 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -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 */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [External] [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth()
  2021-11-18 11:41 [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth() Hans de Goede
  2021-11-18 11:41 ` [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit Hans de Goede
@ 2021-11-18 15:45 ` Mark Pearson
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Pearson @ 2021-11-18 15:45 UTC (permalink / raw)
  To: Hans de Goede, Mark Gross, Andy Shevchenko; +Cc: platform-driver-x86

Thanks Hans

On 2021-11-18 06:41, Hans de Goede wrote:
> 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().
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/platform/x86/think-lmi.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
> index fee9e004161f..6eba69334fa6 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -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 */
> 
Looks good, and works well. Verified with modifying NVMe and Admin
password on M90n

Tested-by: Mark Pearson <markpearson@lenovo.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [External] [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit
  2021-11-18 11:41 ` [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit Hans de Goede
@ 2021-11-18 15:46   ` Mark Pearson
  2021-11-22 12:53     ` Hans de Goede
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Pearson @ 2021-11-18 15:46 UTC (permalink / raw)
  To: Hans de Goede, Mark Gross, Andy Shevchenko; +Cc: platform-driver-x86

Thanks Hans,

On 2021-11-18 06:41, Hans de Goede wrote:
> Creating the tlmi_pwd_setting structs can only fail with -ENOMEM, set
> ret to this once and simplify the error handling a bit.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/platform/x86/think-lmi.c | 26 +++++++++++---------------
>  1 file changed, 11 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
> index 6eba69334fa6..27ab8e4e5b83 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -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 */
> 
Looks good, and works well. Verified with modifying NVMe and Admin
password on M90n

Tested-by: Mark Pearson <markpearson@lenovo.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [External] [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit
  2021-11-18 15:46   ` [External] " Mark Pearson
@ 2021-11-22 12:53     ` Hans de Goede
  0 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2021-11-22 12:53 UTC (permalink / raw)
  To: Mark Pearson, Mark Gross, Andy Shevchenko; +Cc: platform-driver-x86

Hi,

On 11/18/21 16:46, Mark Pearson wrote:
> Thanks Hans,
> 
> On 2021-11-18 06:41, Hans de Goede wrote:
>> Creating the tlmi_pwd_setting structs can only fail with -ENOMEM, set
>> ret to this once and simplify the error handling a bit.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/platform/x86/think-lmi.c | 26 +++++++++++---------------
>>  1 file changed, 11 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
>> index 6eba69334fa6..27ab8e4e5b83 100644
>> --- a/drivers/platform/x86/think-lmi.c
>> +++ b/drivers/platform/x86/think-lmi.c
>> @@ -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 */
>>
> Looks good, and works well. Verified with modifying NVMe and Admin
> password on M90n
> 
> Tested-by: Mark Pearson <markpearson@lenovo.com>

Thank you, I've pushed both patches to my for-next branch now,
with your Tested-by tag added.

Regards,

Hans


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-22 12:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18 11:41 [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth() Hans de Goede
2021-11-18 11:41 ` [PATCH 2/2] platform/x86: think-lmi: Simplify tlmi_analyze() error handling a bit Hans de Goede
2021-11-18 15:46   ` [External] " Mark Pearson
2021-11-22 12:53     ` Hans de Goede
2021-11-18 15:45 ` [External] [PATCH 1/2] platform/x86: think-lmi: Move kobject_init() call into tlmi_create_auth() Mark Pearson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.