mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Li Jun <jun.li@nxp.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: typec: mux: Use device type instead of device name for matching
Date: Mon, 31 May 2021 10:09:19 +0200	[thread overview]
Message-ID: <48e89766-42d0-ce04-53bf-2195a7479296@redhat.com> (raw)
In-Reply-To: <YLSQkynoJO2+hYGW@kuha.fi.intel.com>

Hi,

On 5/31/21 9:30 AM, Heikki Krogerus wrote:
> On Wed, May 26, 2021 at 06:35:47PM +0300, Heikki Krogerus wrote:
>> Both the USB Type-C switch and mux have already a device
>> type defined for them. We can use those types instead of the
>> device name to differentiate the two.
> 
> This should still be OK, right?

I believe so and a dev_type check also seems more robust then
a name-suffix check.

Regards,

Hans


> 
>> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>> ---
>>  drivers/usb/typec/mux.c | 26 ++++++++++----------------
>>  drivers/usb/typec/mux.h |  6 ++++++
>>  2 files changed, 16 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
>> index 8514bec7e1b89..e40a555724fb6 100644
>> --- a/drivers/usb/typec/mux.c
>> +++ b/drivers/usb/typec/mux.c
>> @@ -17,21 +17,12 @@
>>  #include "class.h"
>>  #include "mux.h"
>>  
>> -static bool dev_name_ends_with(struct device *dev, const char *suffix)
>> -{
>> -	const char *name = dev_name(dev);
>> -	const int name_len = strlen(name);
>> -	const int suffix_len = strlen(suffix);
>> -
>> -	if (suffix_len > name_len)
>> -		return false;
>> -
>> -	return strcmp(name + (name_len - suffix_len), suffix) == 0;
>> -}
>> -
>>  static int switch_fwnode_match(struct device *dev, const void *fwnode)
>>  {
>> -	return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-switch");
>> +	if (!is_typec_switch(dev))
>> +		return 0;
>> +
>> +	return dev_fwnode(dev) == fwnode;
>>  }
>>  
>>  static void *typec_switch_match(struct fwnode_handle *fwnode, const char *id,
>> @@ -90,7 +81,7 @@ static void typec_switch_release(struct device *dev)
>>  	kfree(to_typec_switch(dev));
>>  }
>>  
>> -static const struct device_type typec_switch_dev_type = {
>> +const struct device_type typec_switch_dev_type = {
>>  	.name = "orientation_switch",
>>  	.release = typec_switch_release,
>>  };
>> @@ -180,7 +171,10 @@ EXPORT_SYMBOL_GPL(typec_switch_get_drvdata);
>>  
>>  static int mux_fwnode_match(struct device *dev, const void *fwnode)
>>  {
>> -	return dev_fwnode(dev) == fwnode && dev_name_ends_with(dev, "-mux");
>> +	if (!is_typec_mux(dev))
>> +		return 0;
>> +
>> +	return dev_fwnode(dev) == fwnode;
>>  }
>>  
>>  static void *typec_mux_match(struct fwnode_handle *fwnode, const char *id,
>> @@ -295,7 +289,7 @@ static void typec_mux_release(struct device *dev)
>>  	kfree(to_typec_mux(dev));
>>  }
>>  
>> -static const struct device_type typec_mux_dev_type = {
>> +const struct device_type typec_mux_dev_type = {
>>  	.name = "mode_switch",
>>  	.release = typec_mux_release,
>>  };
>> diff --git a/drivers/usb/typec/mux.h b/drivers/usb/typec/mux.h
>> index 4fd9426ee44f6..b1d6e837cb747 100644
>> --- a/drivers/usb/typec/mux.h
>> +++ b/drivers/usb/typec/mux.h
>> @@ -18,4 +18,10 @@ struct typec_mux {
>>  #define to_typec_switch(_dev_) container_of(_dev_, struct typec_switch, dev)
>>  #define to_typec_mux(_dev_) container_of(_dev_, struct typec_mux, dev)
>>  
>> +extern const struct device_type typec_switch_dev_type;
>> +extern const struct device_type typec_mux_dev_type;
>> +
>> +#define is_typec_switch(dev) ((dev)->type == &typec_switch_dev_type)
>> +#define is_typec_mux(dev) ((dev)->type == &typec_mux_dev_type)
>> +
>>  #endif /* __USB_TYPEC_MUX__ */
>> -- 
>> 2.30.2
> 


  reply	other threads:[~2021-05-31  8:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26 15:35 [PATCH 0/2] usb: typec: mux: a few improvements Heikki Krogerus
2021-05-26 15:35 ` [PATCH 1/2] usb: typec: mux: Use device type instead of device name for matching Heikki Krogerus
2021-05-31  7:30   ` Heikki Krogerus
2021-05-31  8:09     ` Hans de Goede [this message]
2021-05-26 15:35 ` [PATCH 2/2] usb: typec: mux: Remove requirement for the "orientation-switch" device property Heikki Krogerus
2021-05-28  7:26   ` Jun Li
2021-05-31  7:24     ` Heikki Krogerus
2021-05-31  7:57       ` Heikki Krogerus
2021-05-31  8:26         ` Heikki Krogerus
2021-05-31 11:08           ` Jun Li
2021-05-31 12:33             ` Heikki Krogerus
2021-05-26 16:38 ` [PATCH 0/2] usb: typec: mux: a few improvements Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48e89766-42d0-ce04-53bf-2195a7479296@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jun.li@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®