The Greybus specification defines the Vendor Specific bundle class[1]. Using this class allows vendors to avoid defining a custom generic class, simplifying driver development. Currently, drivers can register to either match on a bundle class or a Vendor & Product ID with `GREYBUS_CLASS` and `GREYBUS_DEVICE` respectively.
However, when matching to a vendor specific driver, the current implementation does not check the bundle's class. This has the effect of matching the vendor specific driver to ANY bundle found in the device's manifest, regardless of its class. This is incorrect as only vendor class bundles should be considered.
For instance, a driver registered for `GREYBUS_DEVICE(0xCAFE, 0xBABE)` would be matched to a Camera class bundle found on that device. Instead, only a `GREYBUS_CLASS_VENDOR` class bundle should get matched to the driver.
[1] https://github.com/projectara/greybus-spec/blob/149aa4a8f4422533475e0193ecea...
Signed-off-by: Yacin Belmihoub-Martel yacin.belmihoubmartel@gmail.com --- drivers/greybus/core.c | 12 ++++-------- include/linux/greybus.h | 10 +++------- include/linux/greybus/greybus_id.h | 6 ------ 3 files changed, 7 insertions(+), 21 deletions(-)
diff --git a/drivers/greybus/core.c b/drivers/greybus/core.c index 313eb65cf..4cd218d29 100644 --- a/drivers/greybus/core.c +++ b/drivers/greybus/core.c @@ -60,16 +60,12 @@ static int is_gb_svc(const struct device *dev) static bool greybus_match_one_id(struct gb_bundle *bundle, const struct greybus_bundle_id *id) { - if ((id->match_flags & GREYBUS_ID_MATCH_VENDOR) && - (id->vendor != bundle->intf->vendor_id)) + if (id->class != bundle->class) return false;
- if ((id->match_flags & GREYBUS_ID_MATCH_PRODUCT) && - (id->product != bundle->intf->product_id)) - return false; - - if ((id->match_flags & GREYBUS_ID_MATCH_CLASS) && - (id->class != bundle->class)) + if ((id->class == GREYBUS_CLASS_VENDOR) && + (id->vendor != bundle->intf->vendor_id || + id->product != bundle->intf->product_id)) return false;
return true; diff --git a/include/linux/greybus.h b/include/linux/greybus.h index 4d58e27ce..1f1b3cb5c 100644 --- a/include/linux/greybus.h +++ b/include/linux/greybus.h @@ -37,18 +37,14 @@ #define GREYBUS_VERSION_MAJOR 0x00 #define GREYBUS_VERSION_MINOR 0x01
-#define GREYBUS_ID_MATCH_DEVICE \ - (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT) +#define GREYBUS_DEVICE_CLASS(c) \ + .class = (c),
#define GREYBUS_DEVICE(v, p) \ - .match_flags = GREYBUS_ID_MATCH_DEVICE, \ + GREYBUS_DEVICE_CLASS(GREYBUS_CLASS_VENDOR)\ .vendor = (v), \ .product = (p),
-#define GREYBUS_DEVICE_CLASS(c) \ - .match_flags = GREYBUS_ID_MATCH_CLASS, \ - .class = (c), - /* Maximum number of CPorts */ #define CPORT_ID_MAX 4095 /* UniPro max id is 4095 */ #define CPORT_ID_BAD U16_MAX diff --git a/include/linux/greybus/greybus_id.h b/include/linux/greybus/greybus_id.h index f4c844009..e33ed0061 100644 --- a/include/linux/greybus/greybus_id.h +++ b/include/linux/greybus/greybus_id.h @@ -11,7 +11,6 @@
struct greybus_bundle_id { - __u16 match_flags; __u32 vendor; __u32 product; __u8 class; @@ -19,9 +18,4 @@ struct greybus_bundle_id { kernel_ulong_t driver_info __aligned(sizeof(kernel_ulong_t)); };
-/* Used to match the greybus_bundle_id */ -#define GREYBUS_ID_MATCH_VENDOR BIT(0) -#define GREYBUS_ID_MATCH_PRODUCT BIT(1) -#define GREYBUS_ID_MATCH_CLASS BIT(2) - #endif /* __LINUX_GREYBUS_ID_H */