summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extra/i2c_pseudo/Makefile11
-rwxr-xr-xextra/i2c_pseudo/check_stream_open.sh23
-rw-r--r--extra/i2c_pseudo/i2c-pseudo.c13
3 files changed, 46 insertions, 1 deletions
diff --git a/extra/i2c_pseudo/Makefile b/extra/i2c_pseudo/Makefile
index c8dcb1e3b4..f7fda6e2de 100644
--- a/extra/i2c_pseudo/Makefile
+++ b/extra/i2c_pseudo/Makefile
@@ -1,9 +1,20 @@
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Makefile for i2c-pseudo module. Typical usage:
+# $ make
+# $ sudo make modules_install
+# $ make clean
+
obj-m := i2c-pseudo.o
.PHONY: all
all: modules
+CFLAGS_i2c-pseudo.o += "-DHAVE_STREAM_OPEN=$(shell "$M"/check_stream_open.sh)"
+
.DEFAULT:
$(MAKE) -C /lib/modules/$(shell uname -r)/build \
M=$(shell pwd) \
diff --git a/extra/i2c_pseudo/check_stream_open.sh b/extra/i2c_pseudo/check_stream_open.sh
new file mode 100755
index 0000000000..da802cb282
--- /dev/null
+++ b/extra/i2c_pseudo/check_stream_open.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+#
+# Copyright 2020 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# This checks whether stream_open symbol is available from the target kernel.
+#
+# Output meanings:
+# -1 : stream_open is not available
+# 0 : unknown whether or not stream_open is available
+# 1 : stream_open is available
+
+symbols="$(< "/lib/modules/$(uname -r)/build/Module.symvers" \
+ awk '{print $2}' | grep -E '^(nonseekable_open|stream_open)$')"
+
+if echo "${symbols}" | grep -q '^stream_open$'; then
+ echo 1
+elif echo "${symbols}" | grep -q '^nonseekable_open$'; then
+ echo -1
+else
+ echo 0
+fi
diff --git a/extra/i2c_pseudo/i2c-pseudo.c b/extra/i2c_pseudo/i2c-pseudo.c
index 69fc9dbc52..bbe702a14c 100644
--- a/extra/i2c_pseudo/i2c-pseudo.c
+++ b/extra/i2c_pseudo/i2c-pseudo.c
@@ -2205,8 +2205,19 @@ static int i2cp_cdev_open(struct inode *inodep, struct file *filep)
/* Is there any way to find this through @inodep? */
this_pseudo = i2cp_device;
- /* I2C pseudo adapter controllers are not seekable. */
+ /*
+ * HAVE_STREAM_OPEN value meanings:
+ * -1 : stream_open() is not available
+ * 0 : unknown if stream_open() is or is not available
+ * 1 : stream_open() is available
+ */
+#if HAVE_STREAM_OPEN >= 0
+ /* I2C pseudo adapter controllers are non-seekable pure I/O streams. */
stream_open(inodep, filep);
+#else
+ /* I2C pseudo adapter controllers are not seekable. */
+ nonseekable_open(inodep, filep);
+#endif
/* Refuse fsnotify events. Modeled after /dev/ptmx implementation. */
filep->f_mode |= FMODE_NONOTIFY;