git: b5a81075903b - main - LinuxKPI: seq_file add "private" versions.

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 24 Oct 2022 21:42:12 UTC
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=b5a81075903b3d97265151960b731210c0e80244

commit b5a81075903b3d97265151960b731210c0e80244
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-10-22 18:07:37 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-10-24 21:39:48 +0000

    LinuxKPI: seq_file add "private" versions.
    
    Add __seq_open_private() and seq_release_private() needed by iwlwifi
    debugfs support.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
    Reviewed by:    emaste
    Differential Revision: https://reviews.freebsd.org/D37089
---
 .../linuxkpi/common/include/linux/seq_file.h       |  3 ++
 sys/compat/linuxkpi/common/src/linux_seq_file.c    | 33 ++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/seq_file.h b/sys/compat/linuxkpi/common/include/linux/seq_file.h
index e925c6d8c2ae..8fb93646f9a5 100644
--- a/sys/compat/linuxkpi/common/include/linux/seq_file.h
+++ b/sys/compat/linuxkpi/common/include/linux/seq_file.h
@@ -69,6 +69,9 @@ struct seq_operations {
 ssize_t seq_read(struct linux_file *, char *, size_t, off_t *);
 int seq_write(struct seq_file *seq, const void *data, size_t len);
 
+void *__seq_open_private(struct linux_file *, const struct seq_operations *, int);
+int seq_release_private(struct inode *, struct linux_file *);
+
 int seq_open(struct linux_file *f, const struct seq_operations *op);
 int seq_release(struct inode *inode, struct linux_file *file);
 
diff --git a/sys/compat/linuxkpi/common/src/linux_seq_file.c b/sys/compat/linuxkpi/common/src/linux_seq_file.c
index 054917e2fc24..c358e4ae7dc1 100644
--- a/sys/compat/linuxkpi/common/src/linux_seq_file.c
+++ b/sys/compat/linuxkpi/common/src/linux_seq_file.c
@@ -130,6 +130,29 @@ seq_open(struct linux_file *f, const struct seq_operations *op)
 	return (0);
 }
 
+void *
+__seq_open_private(struct linux_file *f, const struct seq_operations *op, int size)
+{
+	struct seq_file *seq_file;
+	void *private;
+	int error;
+
+	private = malloc(size, M_LSEQ, M_NOWAIT|M_ZERO);
+	if (private == NULL)
+		return (NULL);
+
+	error = seq_open(f, op);
+	if (error < 0) {
+		free(private, M_LSEQ);
+		return (NULL);
+	}
+
+	seq_file = (struct seq_file *)f->private_data;
+	seq_file->private = private;
+
+	return (private);
+}
+
 int
 single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d)
 {
@@ -166,6 +189,16 @@ seq_release(struct inode *inode __unused, struct linux_file *file)
 	return (0);
 }
 
+int
+seq_release_private(struct inode *inode __unused, struct linux_file *f)
+{
+	struct seq_file *seq;
+
+	seq = (struct seq_file *)f->private_data;
+	free(seq->private, M_LSEQ);
+	return (seq_release(inode, f));
+}
+
 int
 single_release(struct vnode *v, struct linux_file *f)
 {