All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] backports: explicitely include string.h from device.h
@ 2015-01-25 17:46 Mathieu Olivari
  2015-01-25 17:46 ` [PATCH v2 2/2] backport: add hwmon group registration functions Mathieu Olivari
  0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Olivari @ 2015-01-25 17:46 UTC (permalink / raw)
  To: mcgrof, hauke; +Cc: backports, kvalo, Mathieu Olivari

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.

Signed-off-by: Mathieu Olivari <mathieu@qca.qualcomm.com>

---
 backport/backport-include/linux/device.h |    7 +++++++
 1 file changed, 7 insertions(+)

Notes:
    v2: no changes
diff --git a/backport/backport-include/linux/device.h b/backport/backport-include/linux/device.h
index 29dc077..03ca1f1 100644
--- a/backport/backport-include/linux/device.h
+++ b/backport/backport-include/linux/device.h
@@ -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
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] backport: add hwmon group registration functions
  2015-01-25 17:46 [PATCH v2 1/2] backports: explicitely include string.h from device.h Mathieu Olivari
@ 2015-01-25 17:46 ` Mathieu Olivari
  2015-02-22  2:02   ` Hauke Mehrtens
  0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Olivari @ 2015-01-25 17:46 UTC (permalink / raw)
  To: mcgrof, hauke; +Cc: backports, kvalo, 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.

Signed-off-by: Mathieu Olivari <mathieu@qca.qualcomm.com>

---
 backport/backport-include/linux/hwmon.h |   34 ++++++++++++++++++++
 backport/compat/backport-3.13.c         |   52 +++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+)
 create mode 100644 backport/backport-include/linux/hwmon.h

Notes:
    v2: address the comments reported by Hauke
    *make devm_hwmon_release() static and moved it above
     devm_hwmon_device_register_with_group()
    *moved new includes at the top of the file
    *set dev->groups and drvdata in hwmon_device_register_with_groups()

diff --git a/backport/backport-include/linux/hwmon.h b/backport/backport-include/linux/hwmon.h
new file mode 100644
index 0000000..c0185f1
--- /dev/null
+++ b/backport/backport-include/linux/hwmon.h
@@ -0,0 +1,34 @@
+#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 <linux@roeck-us.net>
+ * 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 <linux@roeck-us.net>
+ */
+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);
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0) */
+
+#endif /* __BACKPORT_LINUX_HWMON_H */
diff --git a/backport/compat/backport-3.13.c b/backport/compat/backport-3.13.c
index 553ed8f..f06269b 100644
--- a/backport/compat/backport-3.13.c
+++ b/backport/compat/backport-3.13.c
@@ -14,6 +14,8 @@
 #include <net/genetlink.h>
 #include <linux/delay.h>
 #include <linux/pci.h>
+#include <linux/device.h>
+#include <linux/hwmon.h>
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0))
 #ifdef CONFIG_REGULATOR
@@ -252,3 +254,53 @@ bool pci_device_is_present(struct pci_dev *pdev)
 }
 EXPORT_SYMBOL_GPL(pci_device_is_present);
 #endif /* CONFIG_PCI */
+
+#ifdef CONFIG_HWMON
+struct device*
+hwmon_device_register_with_groups(struct device *dev, const char *name,
+				  void *drvdata,
+				  const struct attribute_group **groups)
+{
+	struct device *hwdev;
+
+	hwdev = hwmon_device_register(dev);
+	hwdev->groups = groups;
+	dev_set_drvdata(&hwdev, drvdata);
+	return hwdev;
+}
+
+static void devm_hwmon_release(struct device *dev, void *res)
+{
+	struct device *hwdev = *(struct device **)res;
+
+	hwmon_device_unregister(hwdev);
+}
+
+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;
+	devres_add(dev, ptr);
+	return hwdev;
+
+error:
+	devres_free(ptr);
+	return hwdev;
+}
+EXPORT_SYMBOL_GPL(devm_hwmon_device_register_with_groups);
+#endif
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 2/2] backport: add hwmon group registration functions
  2015-01-25 17:46 ` [PATCH v2 2/2] backport: add hwmon group registration functions Mathieu Olivari
@ 2015-02-22  2:02   ` Hauke Mehrtens
  0 siblings, 0 replies; 3+ messages in thread
From: Hauke Mehrtens @ 2015-02-22  2:02 UTC (permalink / raw)
  To: Mathieu Olivari, mcgrof; +Cc: backports, kvalo

On 01/25/2015 06:46 PM, Mathieu Olivari wrote:
> 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.
> 
> Signed-off-by: Mathieu Olivari <mathieu@qca.qualcomm.com>
> 
> ---
>  backport/backport-include/linux/hwmon.h |   34 ++++++++++++++++++++
>  backport/compat/backport-3.13.c         |   52 +++++++++++++++++++++++++++++++
>  2 files changed, 86 insertions(+)
>  create mode 100644 backport/backport-include/linux/hwmon.h
> 
> Notes:
>     v2: address the comments reported by Hauke
>     *make devm_hwmon_release() static and moved it above
>      devm_hwmon_device_register_with_group()
>     *moved new includes at the top of the file
>     *set dev->groups and drvdata in hwmon_device_register_with_groups()
> 

Thank you for the patches. Both were applied to backports and added to
the latest release.

> +	struct device *hwdev;
> +
> +	hwdev = hwmon_device_register(dev);
> +	hwdev->groups = groups;
> +	dev_set_drvdata(&hwdev, drvdata);

I did a small change to this line. hwdev should not be given by double
reference here. I removed the &.

Hauke

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-22  2:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-25 17:46 [PATCH v2 1/2] backports: explicitely include string.h from device.h Mathieu Olivari
2015-01-25 17:46 ` [PATCH v2 2/2] backport: add hwmon group registration functions Mathieu Olivari
2015-02-22  2:02   ` Hauke Mehrtens

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.