Backports Archive on lore.kernel.org
 help / color / Atom feed
From: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
To: hauke@hauke-m.de, mcgrof@kernel.org
Cc: backports@vger.kernel.org,
	Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
Subject: [PATCH] backports: make backports-4.18 compatible with kernel < 3.19
Date: Mon,  6 Jul 2020 11:56:24 +0300
Message-ID: <20200706085624.515714-1-oleksandr.suvorov@toradex.com> (raw)

backports-4.18.c uses ktime_divns() function.
As ktime_divns() is not exported in kernel < 3.19, this symbol
will not be resolved on compat.ko loading.
This commit fixes the linking issue [1].

[1]
-------------------------------
WARNING: "ktime_divns" [compat/compat.ko] undefined!
-------------------------------

Signed-off-by: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
---

 backport/compat/backport-4.18.c | 36 +++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/backport/compat/backport-4.18.c b/backport/compat/backport-4.18.c
index c47fabe5..40551c76 100644
--- a/backport/compat/backport-4.18.c
+++ b/backport/compat/backport-4.18.c
@@ -1,11 +1,47 @@
 /*
  * Copyright (C) 2018 Intel Corporation
+ * Copyright (c) 2020 Toradex
  */
 
 #include <linux/hrtimer.h>
 
+/*
+ * Before the commit 8b618628b2b the ktime_divns was non-exported function.
+ * Add the simple implementation of ktime_divns() to use in
+ * ktime_get_boottime_seconds().
+ */
+#if LINUX_VERSION_IS_LESS(3,19,0)
+
+#include <linux/ktime.h>
+
+#if BITS_PER_LONG < 64
+/*
+ * Divide a ktime value by a nanosecond value
+ */
+u64 ktime_divns(const ktime_t kt, s64 div)
+{
+	int sft = 0;
+	s64 dclc;
+	u64 tmp;
+
+	dclc = ktime_to_ns(kt);
+	tmp = dclc < 0 ? -dclc : dclc;
+
+	/* Make sure the divisor is less than 2^32: */
+	while (div >> 32) {
+		sft++;
+		div >>= 1;
+	}
+	tmp >>= sft;
+	do_div(tmp, (unsigned long) div);
+	return dclc < 0 ? -tmp : tmp;
+}
+#endif /* BITS_PER_LONG >= 64 */
+#endif /* < 3.19 */
+
 time64_t ktime_get_boottime_seconds(void)
 {
 	return ktime_divns(ktime_get_boottime(), NSEC_PER_SEC);
 }
 EXPORT_SYMBOL_GPL(ktime_get_boottime_seconds);
+
-- 
2.25.1

--
To unsubscribe from this list: send the line "unsubscribe backports" in

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06  8:56 Oleksandr Suvorov [this message]
2020-08-08 15:53 ` Hauke Mehrtens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200706085624.515714-1-oleksandr.suvorov@toradex.com \
    --to=oleksandr.suvorov@toradex.com \
    --cc=backports@vger.kernel.org \
    --cc=hauke@hauke-m.de \
    --cc=mcgrof@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Backports Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/backports/0 backports/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 backports backports/ https://lore.kernel.org/backports \
		backports@vger.kernel.org
	public-inbox-index backports

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.backports


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git