init
This commit is contained in:
commit
9c2acf6dd9
|
|
@ -0,0 +1,174 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# NOTE! Don't add files that are generated in specific
|
||||
# subdirectories here. Add them in the ".gitignore" file
|
||||
# in that subdirectory instead.
|
||||
#
|
||||
# NOTE! Please use 'git ls-files -i -c --exclude-per-directory=.gitignore'
|
||||
# command after changing this file, to see if there are
|
||||
# any tracked files which get ignored after the change.
|
||||
#
|
||||
# Normal rules (sorted alphabetically)
|
||||
#
|
||||
.*
|
||||
*.a
|
||||
*.asn1.[ch]
|
||||
*.bin
|
||||
*.bz2
|
||||
*.c.[012]*.*
|
||||
*.cover
|
||||
*.dt.yaml
|
||||
*.dtb
|
||||
*.dtbo
|
||||
*.dtb.S
|
||||
*.dtbo.S
|
||||
*.dwo
|
||||
*.elf
|
||||
*.gcno
|
||||
*.gz
|
||||
*.i
|
||||
*.ko
|
||||
*.lex.c
|
||||
*.ll
|
||||
*.lst
|
||||
*.lz4
|
||||
*.lzma
|
||||
*.lzo
|
||||
*.mbx
|
||||
*.mod
|
||||
*.mod.c
|
||||
*.o
|
||||
*.o.*
|
||||
*.patch
|
||||
*.rmeta
|
||||
*.rpm
|
||||
*.rsi
|
||||
*.s
|
||||
*.so
|
||||
*.so.dbg
|
||||
*.su
|
||||
*.symtypes
|
||||
*.symversions
|
||||
*.tab.[ch]
|
||||
*.tar
|
||||
*.usyms
|
||||
*.xz
|
||||
*.zst
|
||||
Module.symvers
|
||||
modules.order
|
||||
|
||||
#
|
||||
# Top-level generic files
|
||||
#
|
||||
/linux
|
||||
/modules-only.symvers
|
||||
/vmlinux
|
||||
/vmlinux.32
|
||||
/vmlinux.map
|
||||
/vmlinux.symvers
|
||||
/vmlinux-gdb.py
|
||||
/vmlinuz
|
||||
/System.map
|
||||
/Module.markers
|
||||
/modules.builtin
|
||||
/modules.builtin.modinfo
|
||||
/modules.nsdeps
|
||||
|
||||
#
|
||||
# RPM spec file (make rpm-pkg)
|
||||
#
|
||||
/*.spec
|
||||
|
||||
#
|
||||
# Debian directory (make deb-pkg)
|
||||
#
|
||||
/debian/
|
||||
|
||||
#
|
||||
# Snap directory (make snap-pkg)
|
||||
#
|
||||
/snap/
|
||||
|
||||
#
|
||||
# tar directory (make tar*-pkg)
|
||||
#
|
||||
/tar-install/
|
||||
|
||||
#
|
||||
# We don't want to ignore the following even if they are dot-files
|
||||
#
|
||||
!.clang-format
|
||||
!.cocciconfig
|
||||
!.get_maintainer.ignore
|
||||
!.gitattributes
|
||||
!.gitignore
|
||||
!.mailmap
|
||||
!.rustfmt.toml
|
||||
|
||||
#
|
||||
# Generated include files
|
||||
#
|
||||
/include/config/
|
||||
/include/generated/
|
||||
/include/ksym/
|
||||
/arch/*/include/generated/
|
||||
|
||||
# stgit generated dirs
|
||||
patches-*
|
||||
|
||||
# quilt's files
|
||||
patches
|
||||
series
|
||||
|
||||
# ctags files
|
||||
tags
|
||||
TAGS
|
||||
|
||||
# cscope files
|
||||
cscope.*
|
||||
ncscope.*
|
||||
|
||||
# gnu global files
|
||||
GPATH
|
||||
GRTAGS
|
||||
GSYMS
|
||||
GTAGS
|
||||
|
||||
# id-utils files
|
||||
ID
|
||||
|
||||
*.orig
|
||||
*~
|
||||
\#*#
|
||||
|
||||
#
|
||||
# Leavings from module signing
|
||||
#
|
||||
extra_certificates
|
||||
signing_key.pem
|
||||
signing_key.priv
|
||||
signing_key.x509
|
||||
x509.genkey
|
||||
|
||||
# Kconfig presets
|
||||
/all.config
|
||||
/alldef.config
|
||||
/allmod.config
|
||||
/allno.config
|
||||
/allrandom.config
|
||||
/allyes.config
|
||||
|
||||
# Kconfig savedefconfig output
|
||||
/defconfig
|
||||
|
||||
# Kdevelop4
|
||||
*.kdev4
|
||||
|
||||
# Clang's compilation database file
|
||||
/compile_commands.json
|
||||
|
||||
# Documentation toolchain
|
||||
sphinx_*/
|
||||
|
||||
# Rust analyzer configuration
|
||||
/rust-project.json
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
KDIR=/usr/src/kernels/$(shell uname -r)
|
||||
|
||||
obj-m += demo.o
|
||||
|
||||
all:
|
||||
make -C $(KDIR) M=$(shell pwd) modules
|
||||
|
||||
clean:
|
||||
make -C $(KDIR) M=$(shell pwd) clean
|
||||
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/cdev.h>
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
static ssize_t demo_read(struct file *filp, char __user *buff, size_t size, loff_t *pos)
|
||||
{
|
||||
printk("%s %d\n", __func__, __LINE__);
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t demo_write(struct file *filp, const char __user *buff, size_t size, loff_t *pos)
|
||||
{
|
||||
printk("%s %d\n", __func__, __LINE__);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int demo_open(struct inode *inode, struct file *filp)
|
||||
{
|
||||
printk("%s %d\n", __func__, __LINE__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int demo_release(struct inode *inode, struct file *filp)
|
||||
{
|
||||
printk("%s %d\n", __func__, __LINE__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct file_operations demo_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.read = demo_read,
|
||||
.write = demo_write,
|
||||
.open = demo_open,
|
||||
.release = demo_release,
|
||||
};
|
||||
|
||||
static dev_t dev;
|
||||
static struct cdev *cdev;
|
||||
|
||||
int demo_init(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = alloc_chrdev_region(&dev, 0, 1, "demo");
|
||||
if (rc) {
|
||||
printk("failed to alloc chrdev number\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
cdev = cdev_alloc();
|
||||
if (!cdev) {
|
||||
printk("failed to alloc cdev\n");
|
||||
rc = -ENOMEM;
|
||||
goto out_unregister_chrdev;
|
||||
}
|
||||
|
||||
cdev->owner = THIS_MODULE;
|
||||
cdev_init(cdev, &demo_fops);
|
||||
|
||||
rc = cdev_add(cdev, dev, 1);
|
||||
if (rc) {
|
||||
printk("failed to add char device\n");
|
||||
goto out_free_cdev;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out_free_cdev:
|
||||
kobject_put(&cdev->kobj);
|
||||
|
||||
out_unregister_chrdev:
|
||||
unregister_chrdev_region(dev, 1);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void demo_exit(void)
|
||||
{
|
||||
cdev_del(cdev);
|
||||
unregister_chrdev_region(dev, 1);
|
||||
}
|
||||
|
||||
module_init(demo_init);
|
||||
module_exit(demo_exit);
|
||||
Loading…
Reference in New Issue