summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorDominik Sliwa <dominik.sliwa@toradex.com>2018-09-18 17:35:14 +0200
committerDominik Sliwa <dominik.sliwa@toradex.com>2018-09-18 17:55:35 +0200
commit781c0004e3f634ba931e588cc5af49f1268a95e5 (patch)
tree066fc8b3965754aed69e5782c11fa5f7291676c8 /compat
parent69ff0b5709d0d06545fcb2d08c7645b56d3687dd (diff)
mt7601u: compile on tegra 3.1 and 3.10 kernels
Signed-off-by: Dominik Sliwa <dominik.sliwa@toradex.com>
Diffstat (limited to 'compat')
-rw-r--r--compat/backport-4.12.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/compat/backport-4.12.c b/compat/backport-4.12.c
index 8f3e5ab..5cab315 100644
--- a/compat/backport-4.12.c
+++ b/compat/backport-4.12.c
@@ -280,12 +280,77 @@ int bp_extack_genl_unregister_family(struct genl_family *family)
EXPORT_SYMBOL_GPL(bp_extack_genl_unregister_family);
#ifdef CONFIG_OF
+#if LINUX_VERSION_IS_LESS(4,4,0)
+static ssize_t bp_of_device_get_modalias(struct device *dev, char *str, ssize_t len)
+{
+ const char *compat;
+ char *c;
+ struct property *p;
+ ssize_t csize;
+ ssize_t tsize;
+
+ if ((!dev) || (!dev->of_node))
+ return -ENODEV;
+
+ /* Name & Type */
+ csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
+ dev->of_node->type);
+ tsize = csize;
+ len -= csize;
+ if (str)
+ str += csize;
+
+ of_property_for_each_string(dev->of_node, "compatible", p, compat) {
+ csize = strlen(compat) + 1;
+ tsize += csize;
+ if (csize > len)
+ continue;
+
+ csize = snprintf(str, len, "C%s", compat);
+ for (c = str; c; ) {
+ c = strchr(c, ' ');
+ if (c)
+ *c++ = '_';
+ }
+ len -= csize;
+ str += csize;
+ }
+
+ return tsize;
+}
+
+int bp_of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
+{
+ int sl;
+
+ if ((!dev) || (!dev->of_node))
+ return -ENODEV;
+
+ /* Devicetree modalias is tricky, we add it in 2 steps */
+ if (add_uevent_var(env, "MODALIAS="))
+ return -ENOMEM;
+
+ sl = bp_of_device_get_modalias(dev, &env->buf[env->buflen-1],
+ sizeof(env->buf) - env->buflen);
+ if (sl >= (sizeof(env->buf) - env->buflen))
+ return -ENOMEM;
+ env->buflen += sl;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(bp_of_device_uevent_modalias);
+#endif
+
/**
* of_device_modalias - Fill buffer with newline terminated modalias string
*/
ssize_t bp_of_device_modalias(struct device *dev, char *str, ssize_t len)
{
+#if LINUX_VERSION_IS_LESS(4,4,0)
+ ssize_t sl = bp_of_device_get_modalias(dev, str, len - 2);
+#else
ssize_t sl = of_device_get_modalias(dev, str, len - 2);
+#endif
if (sl < 0)
return sl;
if (sl > len - 2)