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/149aa4a8f4422533475e0193ece…
Signed-off-by: Yacin Belmihoub-Martel <yacin.belmihoubmartel(a)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 */
--
2.52.0
Replace sprintf() with sysfs_emit() in the protocol_id_show() sysfs
attribute function. This code is safe as-is, but replace
sprintf() with sysfs_emit() because we are trying to get rid of calls
to sprintf() as part of kernel hardening; sysfs_emit() is more
appropriate in this context.
Signed-off-by: Neel Bullywon <neelb2403(a)gmail.com>
---
This was compile-tested only (no VM/hardware used)
Changes in v2:
- Subject: change to imperative "Replace" (was "Replaced").
- Wording and line breaks adjusted in the commit body for clarity.
Changes in v3:
- Clarify what "safe" means (buffer is PAGE_SIZE) per Dan Carpenter's
suggestion.
- Reflow lines to avoid awkward breaks.
---
drivers/staging/greybus/gbphy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/greybus/gbphy.c b/drivers/staging/greybus/gbphy.c
index 60cf09a302a7..55f132b09cee 100644
--- a/drivers/staging/greybus/gbphy.c
+++ b/drivers/staging/greybus/gbphy.c
@@ -31,7 +31,7 @@ static ssize_t protocol_id_show(struct device *dev,
{
struct gbphy_device *gbphy_dev = to_gbphy_dev(dev);
- return sprintf(buf, "0x%02x\n", gbphy_dev->cport_desc->protocol_id);
+ return sysfs_emit(buf, "0x%02x\n", gbphy_dev->cport_desc->protocol_id);
}
static DEVICE_ATTR_RO(protocol_id);
base-commit: de0674d9bc69699c497477d45172493393ae9007
--
2.44.0
This series fixes checkpatch.pl checks highlighted for files
in greybus, for mutex declaration comments, and styling issues.
Changes in v3:
- Added cover letter detailing changes made in subsequent versions of
patch-sets.
- v2 patch-set was only emailed to maintainers. The email was forwarded
to the lists, but this rendered the patch-set corrupted. v3 hopes to
correct this.
Changes in v2:
- Split patch 1 into two individual patches 1/4 and 2/4 to keep logical
changes separate.
Rachit Dhar (4):
staging: greybus: added comment to mutex declaration in
fw-management.c
staging: greybus: fixed styling issue in fw-management.c
staging: greybus: resolved checkpatch checks for raw.c
staging: greybus: resolved checkpatch checks for light.c
drivers/staging/greybus/fw-management.c | 5 +++--
drivers/staging/greybus/light.c | 4 ++--
drivers/staging/greybus/raw.c | 2 +-
3 files changed, 6 insertions(+), 5 deletions(-)
--
2.43.0
Replaced sprintf() with sysfs_emit() in the protocol_id_show() sysfs
attribute function. This code is safe, as replacing sprintf() with
sysfs_emit() gets rid of calls to sprintf()
as part of kernel hardening and sysfs_emit() is more appropriate in
this context.
Signed-off-by: Neel Bullywon <neelb2403(a)gmail.com>
---
This was compile-tested only (no VM/hardware used)
---
drivers/staging/greybus/gbphy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/greybus/gbphy.c b/drivers/staging/greybus/gbphy.c
index 60cf09a302a7..55f132b09cee 100644
--- a/drivers/staging/greybus/gbphy.c
+++ b/drivers/staging/greybus/gbphy.c
@@ -31,7 +31,7 @@ static ssize_t protocol_id_show(struct device *dev,
{
struct gbphy_device *gbphy_dev = to_gbphy_dev(dev);
- return sprintf(buf, "0x%02x\n", gbphy_dev->cport_desc->protocol_id);
+ return sysfs_emit(buf, "0x%02x\n", gbphy_dev->cport_desc->protocol_id);
}
static DEVICE_ATTR_RO(protocol_id);
--
2.44.0