Skip to contentSkip to conversation

batman-adv: convert stream-like files from nonseekable_open -> stream_open

PATCH New Sven Eckelmann 1 participant 1 message May 11, 2019 Batman advanced

lore
Share & tools
lore

Sven Eckelmann

author maintainer
#0 lore raw

PATCH 1/1 batman-adv: convert stream-like files from nonseekable_open -> stream_open

From: Kirill Smelkov <[email protected]>

Using scripts/coccinelle/api/stream_open.cocci added in 10dce8af3422 ("fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock"), search and convert to stream_open all in-kernel nonseekable_open users for which read and write actually do not depend on ppos and where there is no other methods in file_operations which assume @offset access.

I've verified each generated change manually - that it is correct to convert - and each other nonseekable_open instance left - that it is either not correct to convert there, or that it is not converted due to current stream_open.cocci limitations.

One can also recheck/review the patch via generating it with explanation comments included via

	$ make coccicheck MODE=patch COCCI=scripts/coccinelle/api/stream_open.cocci SPFLAGS="-D explain"

---
This change is already upstream
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/patch/?id=c5bf68fe0c86a5835bd2e6aead1c49976360753f

---
 compat-include/linux/fs.h    | 11 +++++++++++
 net/batman-adv/icmp_socket.c |  2 +-
 net/batman-adv/log.c         |  2 +-
 3 files changed, 13 insertions(+), 2 deletions(-)
compat-include/linux/fs.h +11 -0
index c52e0e8e..480722f0 100644
@@ -31,4 +31,15 @@ static inline struct dentry *batadv_file_dentry(const struct file *file)
 
 #endif /* < KERNEL_VERSION(4, 6, 0) */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0)
+
+static inline int batadv_stream_open(struct inode *inode, struct file *filp)
+{
+	return nonseekable_open(inode, filp);
+}
+
+#define stream_open batadv_stream_open
+
+#endif /* < KERNEL_VERSION(5, 2, 0) */
+
 #endif	/* _NET_BATMAN_ADV_COMPAT_LINUX_FS_H_ */
net/batman-adv/icmp_socket.c +1 -1
index de81b5ec..0a91c866 100644
@@ -65,7 +65,7 @@ static int batadv_socket_open(struct inode *inode, struct file *file)
 
 	batadv_debugfs_deprecated(file, "");
 
-	nonseekable_open(inode, file);
+	stream_open(inode, file);
 
 	socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL);
 	if (!socket_client) {
net/batman-adv/log.c +1 -1
index 60ce11e1..f79ebd5b 100644
@@ -90,7 +90,7 @@ static int batadv_log_open(struct inode *inode, struct file *file)
 	batadv_debugfs_deprecated(file,
 				  "Use tracepoint batadv:batadv_dbg instead\n");
 
-	nonseekable_open(inode, file);
+	stream_open(inode, file);
 	file->private_data = inode->i_private;
 	return 0;
 }
Signature · 1 line
2.20.1