Skip to contentSkip to conversation

backports: explicitely include string.h from device.h

PATCH Superseded Mathieu Olivari 2 participants 3 messages Jan 13, 2015 – Jan 23, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 backports: explicitely include string.h from device.h

string.h is usually included from the asm/ folder in most configuration, but on some older kernels and non-x86 architecture, this inclusion is not necessarily happening. As we're using memcpy() in the code below, we need to be safe and make sure string.h is indeed there.

This issue has been observed on a 3.4 vendor kernels, but may be applicable to other configurations.

---
 backport/backport-include/linux/device.h |    7 +++++++
 1 file changed, 7 insertions(+)
backport/backport-include/linux/device.h +7 -0
index 29dc077..03ca1f1 100644
@@ -5,6 +5,13 @@
 
 #include <linux/version.h>
 
+/*
+ * string.h is usually included from the asm/ folder in most configuration,
+ * but on some older kernels it doesn't. As we're using memcpy() in the code
+ * below, we need to be safe and make sure string.h is indeed there.
+ */
+#include <linux/string.h>
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
 /* backport
  * commit 9f3b795a626ee79574595e06d1437fe0c7d51d29
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 backport: add hwmon group registration functions

hwmon group registration functions have been added in 3.13 kernel. Latest ath10k patches make use of this mechanism, therefore the need for the backport.

---
 backport/backport-include/linux/hwmon.h |   36 +++++++++++++++++++++++
 backport/compat/backport-3.13.c         |   47 +++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 backport/backport-include/linux/hwmon.h
backport/backport-include/linux/hwmon.h new file +36 -0
new file mode 100644
index 0000000..961e979
@@ -0,0 +1,36 @@
+#ifndef __BACKPORT_LINUX_HWMON_H
+#define __BACKPORT_LINUX_HWMON_H
+#include_next <linux/hwmon.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
+/*
+ * Backports
+ *
+ * commit bab2243ce1897865e31ea6d59b0478391f51812b
+ * Author: Guenter Roeck <[email protected]>
+ * Date:   Sat Jul 6 13:57:23 2013 -0700
+ *
+ *     hwmon: Introduce hwmon_device_register_with_groups
+ *
+ *     hwmon_device_register_with_groups() lets callers register a hwmon device
+ *     together with all sysfs attributes in a single call.
+ *
+ *     When using hwmon_device_register_with_groups(), hwmon attributes are attached
+ *     to the hwmon device directly and no longer with its parent device.
+ *
+ * Signed-off-by: Guenter Roeck <[email protected]>
+ */
+struct device *
+hwmon_device_register_with_groups(struct device *dev, const char *name,
+				  void *drvdata,
+				  const struct attribute_group **groups);
+struct device *
+devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
+				       void *drvdata,
+				       const struct attribute_group **groups);
+void devm_hwmon_release(struct device *dev, void *res);
+
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0) */
+
+#endif /* __BACKPORT_LINUX_HWMON_H */
backport/compat/backport-3.13.c +47 -0

50 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 2/2] backport: add hwmon group registration functions

Quoted 39 lines · Mathieu Olivari

hwmon group registration functions have been added in 3.13 kernel. Latest ath10k patches make use of this mechanism, therefore the need for the backport.

---
 backport/backport-include/linux/hwmon.h |   36 +++++++++++++++++++++++
 backport/compat/backport-3.13.c         |   47 +++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)
 create mode 100644 backport/backport-include/linux/hwmon.h
backport/backport-include/linux/hwmon.h new file +22 -0
new file mode 100644
index 0000000..961e979
@@ -0,0 +1,36 @@
+#ifndef __BACKPORT_LINUX_HWMON_H
+#define __BACKPORT_LINUX_HWMON_H
+#include_next <linux/hwmon.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
+/*
+ * Backports
+ *
+ * commit bab2243ce1897865e31ea6d59b0478391f51812b
+ * Author: Guenter Roeck <[email protected]>
+ * Date:   Sat Jul 6 13:57:23 2013 -0700
+ *
+ *     hwmon: Introduce hwmon_device_register_with_groups
+ *
+ *     hwmon_device_register_with_groups() lets callers register a hwmon device
+ *     together with all sysfs attributes in a single call.
+ *
+ *     When using hwmon_device_register_with_groups(), hwmon attributes are attached
+ *     to the hwmon device directly and no longer with its parent device.
+ *
+ * Signed-off-by: Guenter Roeck <[email protected]>

backport/backport-include/linux/hwmon.h line 32

Quoted 10 lines
backport/backport-include/linux/hwmon.h new file +10 -0
+ */
+struct device *
+hwmon_device_register_with_groups(struct device *dev, const char *name,
+				  void *drvdata,
+				  const struct attribute_group **groups);
+struct device *
+devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
+				       void *drvdata,
+				       const struct attribute_group **groups);
+void devm_hwmon_release(struct device *dev, void *res);

devm_hwmon_release() can get removed here when you make it static.

Quoted 9 lines
backport/backport-include/linux/hwmon.h new file +4 -0
+
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0) */
+
+#endif /* __BACKPORT_LINUX_HWMON_H */
backport/compat/backport-3.13.c +0 -0
index 553ed8f..89100a2 100644

backport/compat/backport-3.13.c bool pci_device_is_present(struct pci_dev *pdev) · line 258

Quoted 7 lines
backport/compat/backport-3.13.c +4 -0
@@ -252,3 +252,50 @@ bool pci_device_is_present(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL_GPL(pci_device_is_present);
 #endif /* CONFIG_PCI */
+
+#ifdef CONFIG_HWMON
+#include <linux/device.h>
+#include <linux/hwmon.h>

You can move the includes to the top of the file.

backport/compat/backport-3.13.c bool pci_device_is_present(struct pci_dev *pdev) · line 264

Quoted 6 lines
backport/compat/backport-3.13.c +6 -0
+struct device*
+hwmon_device_register_with_groups(struct device *dev, const char *name,
+				  void *drvdata,
+				  const struct attribute_group **groups)
+{
+	return hwmon_device_register(dev);

You should probably set dev->groups and the drvdata.

Quoted 21 lines
backport/compat/backport-3.13.c +21 -0
+}
+
+struct device *
+devm_hwmon_device_register_with_groups(struct device *dev, const char *name,
+				       void *drvdata,
+				       const struct attribute_group **groups)
+{
+	struct device **ptr, *hwdev;
+
+	if (!dev)
+		return ERR_PTR(-EINVAL);
+
+	ptr = devres_alloc(devm_hwmon_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return ERR_PTR(-ENOMEM);
+
+	hwdev = hwmon_device_register_with_groups(dev, name, drvdata, groups);
+	if (IS_ERR(hwdev))
+		goto error;
+
+	*ptr = hwdev;

backport/compat/backport-3.13.c bool pci_device_is_present(struct pci_dev *pdev) · line 295

Quoted 10 lines
backport/compat/backport-3.13.c +10 -0
+	devres_add(dev, ptr);
+	return hwdev;
+
+error:
+	devres_free(ptr);
+	return hwdev;
+}
+EXPORT_SYMBOL_GPL(devm_hwmon_device_register_with_groups);
+
+void devm_hwmon_release(struct device *dev, void *res)

You should make this function static and move it before devm_hwmon_device_register_with_group().

Quoted 7 lines
backport/compat/backport-3.13.c +6 -0
+{
+	struct device *hwdev = *(struct device **)res;
+
+	hwmon_device_unregister(hwdev);
+}
+#endif