Skip to contentSkip to conversation

samples: add a sample list module

PATCH New David Heidelberg 1 participant 1 message Dec 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 samples: add a sample list module

Sample list module that creates a proc entry /proc/sample_list and registers read/write file operations.

Each write to the proc will copy the buffer
and store it in a data structure.

Each read from the proc will populate the read buffer with list entries, up to the read length (buffer size).

---
I would love to receive feedback on this list implementation approach. If there are any implementation mistakes, I am open to revising this sample to make it more accurate.

 samples/Kconfig       |  13 +++++
 samples/Makefile      |   1 +
 samples/list/Makefile |   2 +
 samples/list/list.c   | 125 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 141 insertions(+)
 create mode 100644 samples/list/Makefile
 create mode 100644 samples/list/list.c
samples/Kconfig +13 -0
index b288d9991d27..7bc9c2c85599 100644
@@ -128,6 +128,19 @@ config SAMPLE_RPMSG_CLIENT
 	  to communicate with an AMP-configured remote processor over
 	  the rpmsg bus.
 
+config SAMPLE_LIST
+	tristate "Build list implementation sample"
+	depends on PROC_FS
+	help
+	  Build a sample list module that creates a proc entry
+	  /proc/sample_list and registers read/write file operations.
+
+	  Each write to the proc will copy the buffer
+	  and store it in a data structure.
+
+	  Each read from the proc will populate the read buffer with
+	  list entries, up to the read length (buffer size).
+
 config SAMPLE_LIVEPATCH
 	tristate "Build live patching samples -- loadable modules only"
 	depends on LIVEPATCH && m
samples/Makefile +1 -0
index b85fa64390c5..68158af60c96 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_SAMPLE_KFIFO)		+= kfifo/
 obj-$(CONFIG_SAMPLE_KOBJECT)		+= kobject/
 obj-$(CONFIG_SAMPLE_KPROBES)		+= kprobes/
 subdir-$(CONFIG_SAMPLE_LANDLOCK)	+= landlock
+obj-$(CONFIG_SAMPLE_LIST)		+= list/
 obj-$(CONFIG_SAMPLE_LIVEPATCH)		+= livepatch/
 subdir-$(CONFIG_SAMPLE_PIDFD)		+= pidfd
 obj-$(CONFIG_SAMPLE_QMI_CLIENT)		+= qmi/
samples/list/Makefile new file +2 -0
new file mode 100644
index 000000000000..8e77d97aaa9c
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_SAMPLE_LIST) += list.o
samples/list/list.c new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.45.2