Re: [PATCH v2] alienware-wmi: Dell AWCC platform_profile support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Removed.

> > +static int platform_profile_get(struct platform_profile_handler *pprof,
> > +				enum platform_profile_option *profile)
> > +{
> > +	acpi_status status;
> > +	u32 in_args = 0x0B;
> 
> Use a named define instead of a magic number.
> 

Done

> > +	u32 out_data;
> > +
> > +	status = alienware_wmax_command(&in_args, sizeof(in_args),
> > +					WMAX_METHOD_THERMAL_INFORMATION, (u32 *) &out_data);
> 
> Casting to the same type??
> 
> Also, alienware_wmax_command() inputs int * which makes the cast look even 
> more odd?!?
> 
> I can see there are pre-existing bogus (u32 *) casts too which would be 
> nice to clean up in another patch.
> 

Yes I thought it was odd but added them just in case. I can submit a
patch cleaning those up after this one.

> > +
> > +	if (ACPI_FAILURE(status) || out_data < 0)
> 
> u32 cannot be < 0??
> 
> Is this an indication of a problem in the error handling?
> 

Yes it was, thank you for catching it.

> > +		return -EOPNOTSUPP;
> > +
> > +	switch (out_data) {
> > +	case WMAX_THERMAL_LOW_POWER:
> > +		*profile = PLATFORM_PROFILE_LOW_POWER;
> > +		break;
> > +	case WMAX_THERMAL_QUIET:
> > +		*profile = PLATFORM_PROFILE_QUIET;
> > +		break;
> > +	case WMAX_THERMAL_BALANCED:
> > +		*profile = PLATFORM_PROFILE_BALANCED;
> > +		break;
> > +	case WMAX_THERMAL_BALANCED_PERFORMANCE:
> > +		*profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE;
> > +		break;
> > +	case WMAX_THERMAL_PERFORMANCE:
> > +	case WMAX_THERMAL_GMODE:
> > +		*profile = PLATFORM_PROFILE_PERFORMANCE;
> > +		break;
> > +	default:
> > +		return -ENODATA;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +#define SET_MASK(prof) ((prof << 8) | 1)
> 
> Name these with two defines. One define for naming that magic 1 and 
> another for the profile field, use GENMASK() + FIELD_PREP() for it.
> 
> Also, there's no need for this to be macro so change it into a static 
> function.
> 

Done.

> > +static int platform_profile_set(struct platform_profile_handler *pprof,
> > +				enum platform_profile_option profile)
> > +{
> > +	acpi_status status;
> > +	u32 in_args;
> > +	u32 out_data;
> > +
> > +	switch (profile) {
> > +	case PLATFORM_PROFILE_LOW_POWER:
> > +		in_args = SET_MASK(WMAX_THERMAL_LOW_POWER);
> > +		break;
> > +	case PLATFORM_PROFILE_QUIET:
> > +		in_args = SET_MASK(WMAX_THERMAL_QUIET);
> > +		break;
> > +	case PLATFORM_PROFILE_BALANCED:
> > +		in_args = SET_MASK(WMAX_THERMAL_BALANCED);
> > +		break;
> > +	case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
> > +		in_args = SET_MASK(WMAX_THERMAL_BALANCED_PERFORMANCE);
> > +		break;
> > +	case PLATFORM_PROFILE_PERFORMANCE:
> > +		in_args = SET_MASK(WMAX_THERMAL_PERFORMANCE);
> > +		break;
> > +	default:
> > +		return -EOPNOTSUPP;
> > +	}
> > +
> > +	status = alienware_wmax_command(&in_args, sizeof(in_args),
> > +					WMAX_METHOD_THERMAL_CONTROL, (u32 *) &out_data);
> 
> Cast to same type.
> 
> > +
> > +	if (ACPI_FAILURE(status) || out_data < 0)
> 
> u32 cannot be < 0.
> 
> > +		return -EOPNOTSUPP;
> > +
> > +	return 0;
> > +}
> > +
> > +static int gmode_platform_profile_set(struct platform_profile_handler *pprof,
> > +				      enum platform_profile_option profile)
> > +{
> > +	acpi_status status;
> > +	u32 in_args;
> > +	u32 out_data;
> > +
> > +	switch (profile) {
> > +	case PLATFORM_PROFILE_LOW_POWER:
> > +		in_args = SET_MASK(WMAX_THERMAL_LOW_POWER);
> > +		break;
> > +	case PLATFORM_PROFILE_QUIET:
> > +		in_args = SET_MASK(WMAX_THERMAL_QUIET);
> > +		break;
> > +	case PLATFORM_PROFILE_BALANCED:
> > +		in_args = SET_MASK(WMAX_THERMAL_BALANCED);
> > +		break;
> > +	case PLATFORM_PROFILE_BALANCED_PERFORMANCE:
> > +		in_args = SET_MASK(WMAX_THERMAL_BALANCED_PERFORMANCE);
> > +		break;
> > +	case PLATFORM_PROFILE_PERFORMANCE:
> > +		in_args = SET_MASK(WMAX_THERMAL_GMODE);
> > +		break;
> > +	default:
> > +		return -EOPNOTSUPP;
> > +	}
> > +
> > +	status = alienware_wmax_command(&in_args, sizeof(in_args),
> 
> > +					WMAX_METHOD_THERMAL_CONTROL, (u32 *) &out_data);
> > +	if (ACPI_FAILURE(status) || out_data < 0)
> 
> The same two issues here with the types.
> 
> > +		return -EOPNOTSUPP;
> > +
> > +	return 0;
> > +}
> > +
> > +static int create_platform_profile(void)
> > +{
> > +	pp_handler.profile_get = platform_profile_get;
> > +
> > +	if (quirks->gmode > 0)
> > +		pp_handler.profile_set = gmode_platform_profile_set;
> > +	else
> > +		pp_handler.profile_set = platform_profile_set;
> > +
> > +	set_bit(PLATFORM_PROFILE_LOW_POWER, pp_handler.choices);
> > +	set_bit(PLATFORM_PROFILE_QUIET, pp_handler.choices);
> > +	set_bit(PLATFORM_PROFILE_BALANCED, pp_handler.choices);
> > +	set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, pp_handler.choices);
> > +	set_bit(PLATFORM_PROFILE_PERFORMANCE, pp_handler.choices);
> > +
> > +	return platform_profile_register(&pp_handler);
> > +}
> > +
> >  static int __init alienware_wmi_init(void)
> >  {
> >  	int ret;
> > @@ -807,6 +987,12 @@ static int __init alienware_wmi_init(void)
> >  			goto fail_prep_deepsleep;
> >  	}
> >  
> > +	if (quirks->thermal > 0) {
> > +		ret = create_platform_profile();
> > +		if (ret)
> > +			goto fail_prep_thermal_profile;
> > +	}
> > +
> >  	ret = alienware_zone_init(platform_device);
> >  	if (ret)
> >  		goto fail_prep_zones;
> > @@ -817,6 +1003,7 @@ static int __init alienware_wmi_init(void)
> >  	alienware_zone_exit(platform_device);
> >  fail_prep_deepsleep:
> >  fail_prep_amplifier:
> > +fail_prep_thermal_profile:
> >  fail_prep_hdmi:
> >  	platform_device_del(platform_device);
> >  fail_platform_device2:
> > @@ -836,6 +1023,7 @@ static void __exit alienware_wmi_exit(void)
> >  		remove_hdmi(platform_device);
> >  		platform_device_unregister(platform_device);
> >  		platform_driver_unregister(&platform_driver);
> > +		platform_profile_remove();
> 
> IIRC, I once checked that this will lead to a crash if it wasn't created 
> first (which in your driver isn't always the case).
> 

Fixed.

> -- 
>  i.

Thank you for your feedback. I will submit v3 with the corrections soon.

Kurt




[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux