From 781c0004e3f634ba931e588cc5af49f1268a95e5 Mon Sep 17 00:00:00 2001 From: Dominik Sliwa Date: Tue, 18 Sep 2018 17:35:14 +0200 Subject: mt7601u: compile on tegra 3.1 and 3.10 kernels Signed-off-by: Dominik Sliwa --- compat/backport-4.12.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'compat') 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) -- cgit v1.2.3