diff mbox series

[v1,3/5] Bluetooth: hci_bcm: Use serdev_acpi_get_uart_resource() helper

Message ID 20210803192905.72246-3-andriy.shevchenko@linux.intel.com (mailing list archive)
State Superseded, archived
Headers show
Series [v1,1/5] serdev: Split and export serdev_acpi_get_uart_resource() | expand

Commit Message

Andy Shevchenko Aug. 3, 2021, 7:29 p.m. UTC
serdev provides a generic helper to get UART Serial Bus resources.
Use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/bluetooth/hci_bcm.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Hans de Goede Aug. 4, 2021, 8:12 a.m. UTC | #1
Hi,

On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> serdev provides a generic helper to get UART Serial Bus resources.
> Use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/bluetooth/hci_bcm.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
> index 3cd57fc56ade..16f854ac19b6 100644
> --- a/drivers/bluetooth/hci_bcm.c
> +++ b/drivers/bluetooth/hci_bcm.c
> @@ -899,9 +899,9 @@ static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
>  static int bcm_resource(struct acpi_resource *ares, void *data)
>  {
>  	struct bcm_device *dev = data;
> +	struct acpi_resource_uart_serialbus *uart;
>  	struct acpi_resource_extended_irq *irq;
>  	struct acpi_resource_gpio *gpio;
> -	struct acpi_resource_uart_serialbus *sb;
>  
>  	switch (ares->type) {
>  	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
> @@ -920,18 +920,15 @@ static int bcm_resource(struct acpi_resource *ares, void *data)
>  		dev->gpio_count++;
>  		break;
>  
> -	case ACPI_RESOURCE_TYPE_SERIAL_BUS:
> -		sb = &ares->data.uart_serial_bus;
> -		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
> -			dev->init_speed = sb->default_baud_rate;
> -			dev->oper_speed = 4000000;
> -		}
> -		break;
> -
>  	default:
>  		break;
>  	}
>  
> +	if (serdev_acpi_get_uart_resource(ares, &uart)) {
> +		dev->init_speed = uart->default_baud_rate;
> +		dev->oper_speed = 4000000;
> +	}
> +

You are replacing a nice switch-case which handles all relevant resource
types with still having a switch-case + a separate if .. else if .. else if ...
(also taking patch 4/5 into account).

This does not help the readability of this code at all IMHO, so NACK
from me for this patch as well as for 4/5.

Regards,

Hans
Andy Shevchenko Aug. 4, 2021, 8:42 a.m. UTC | #2
On Wed, Aug 4, 2021 at 11:13 AM Hans de Goede <hdegoede@redhat.com> wrote:
> On 8/3/21 9:29 PM, Andy Shevchenko wrote:
> > serdev provides a generic helper to get UART Serial Bus resources.
> > Use it instead of open coded variant.

...

> > +     if (serdev_acpi_get_uart_resource(ares, &uart)) {
> > +             dev->init_speed = uart->default_baud_rate;
> > +             dev->oper_speed = 4000000;
> > +     }
> > +
>
> You are replacing a nice switch-case which handles all relevant resource
> types with still having a switch-case + a separate if .. else if .. else if ...
> (also taking patch 4/5 into account).
>
> This does not help the readability of this code at all IMHO, so NACK
> from me for this patch as well as for 4/5.

I guess it's a matter of style. The main idea is to try avoiding the
spreading of the customized ACPI resource extraction here and there.
Probably I should have started with cleaning up the EXTENDED_IRQ case,
which seems not needed here in the current form.
Hans de Goede Aug. 4, 2021, 9:35 a.m. UTC | #3
Hi,

On 8/4/21 10:42 AM, Andy Shevchenko wrote:
> On Wed, Aug 4, 2021 at 11:13 AM Hans de Goede <hdegoede@redhat.com> wrote:
>> On 8/3/21 9:29 PM, Andy Shevchenko wrote:
>>> serdev provides a generic helper to get UART Serial Bus resources.
>>> Use it instead of open coded variant.
> 
> ...
> 
>>> +     if (serdev_acpi_get_uart_resource(ares, &uart)) {
>>> +             dev->init_speed = uart->default_baud_rate;
>>> +             dev->oper_speed = 4000000;
>>> +     }
>>> +
>>
>> You are replacing a nice switch-case which handles all relevant resource
>> types with still having a switch-case + a separate if .. else if .. else if ...
>> (also taking patch 4/5 into account).
>>
>> This does not help the readability of this code at all IMHO, so NACK
>> from me for this patch as well as for 4/5.
> 
> I guess it's a matter of style. The main idea is to try avoiding the
> spreading of the customized ACPI resource extraction here and there.

I agree that the helpers make sense for drivers which care about 1
specific type of resource like an I2cSerialBus resource.

But in cases like this where the driver cares about all the resources
in the resource-list just doing a switch-case on the resource-type
directly in the driver just seems cleaner and it certainly is
easier to read. Helpers are nice, but every level of indirection
also means that a developer needs to go and find the function and
lookup what it does when they want to know what is exactly happening.

So lining up all these factors then just sticking with the
switch-case here seems best IMHO.

Also when there is doubt if a cleanup actually makes things
better, which there seems to be here, then it is best to simply
stick with what we have since every code-change may introduce
regressions, may make backporting fixes later more difficult, etc.

Regards,

Hans
diff mbox series

Patch

diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 3cd57fc56ade..16f854ac19b6 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -899,9 +899,9 @@  static const struct acpi_gpio_mapping acpi_bcm_int_first_gpios[] = {
 static int bcm_resource(struct acpi_resource *ares, void *data)
 {
 	struct bcm_device *dev = data;
+	struct acpi_resource_uart_serialbus *uart;
 	struct acpi_resource_extended_irq *irq;
 	struct acpi_resource_gpio *gpio;
-	struct acpi_resource_uart_serialbus *sb;
 
 	switch (ares->type) {
 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
@@ -920,18 +920,15 @@  static int bcm_resource(struct acpi_resource *ares, void *data)
 		dev->gpio_count++;
 		break;
 
-	case ACPI_RESOURCE_TYPE_SERIAL_BUS:
-		sb = &ares->data.uart_serial_bus;
-		if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_UART) {
-			dev->init_speed = sb->default_baud_rate;
-			dev->oper_speed = 4000000;
-		}
-		break;
-
 	default:
 		break;
 	}
 
+	if (serdev_acpi_get_uart_resource(ares, &uart)) {
+		dev->init_speed = uart->default_baud_rate;
+		dev->oper_speed = 4000000;
+	}
+
 	return 0;
 }