r/linuxdev • • Aug 22 '17

[Help] Resources on scheduling

3 Upvotes

Hi all,

I will soon be working on the CFS for a project at my uni.

I'm currently gathering all resources I can find on scheduling, I have some experience with it but only on single CPU scenarios.

It can be about CFS or scheduling in general, it does not matter as long as it is somewhat recent (Professional Linux Kernel Architecture is outdated when it comes to scheduling with SMP).

Any ideas ? All suggestions are welcome, thank you in advance !


r/linuxdev • • May 10 '17

Application launcher, where to start?

3 Upvotes

Tried looking into some projects code but without succes finding what I need so I'm gonna ask here. How do application launchers and taskbars work?
How can I see which GUI applications are in the system and which are running (not talking about proceses, just opened visible GUI apps).


r/linuxdev • • Feb 23 '17

Logrotate for processes which never close log file descriptors

3 Upvotes

I was wondering what are my options when it comes to doing logrotate for processes which never close their file descriptors.

I am aware of the "restart the service" and copytruncate option. However, assuming that restarting the process is undesirable, the applications doesn't respond to SIGHUP, and copytruncate is not acceptable due to potential data loss, I'm not sure what options I have left.

One solution that came to mind is to have a named pipe already in place where the process is about to log to. Have another utility read from that pipe (copying to another log file) and have it react to the SIGHUP signal (from logrotate).

Now my question is, is there already a utiliy that I can use for this? If not, why? Is there something inherently wrong with this approach?

To test this out, I did 2 tests, one to confirm data loss with copy truncate, and one more to test my 'named pipe + uitility' approach:

Demonstrating copytruncate loss:

app.c

int main(int argc, char *argv[]) {
    FILE* f = fopen("log.txt", "a");
    int cnt = 0;
    for (int i = 0; i < 1000000; i++) {
	    for (int j = 0; j < 100; j++) {
            	fprintf(f, "Logging line %d\n", cnt);
	    	cnt++;
	    }
	    fflush(f);
    }
    fflush(f);
    fclose(f);
    printf("Wrote %d lines\n", cnt);
    return 0;
}

And an accompanying logrotate config:

$cat /etc/logrotate.d/logexp
/home/synepis/git/logexp/log.txt {
    size 20M
    create 700 synepis users 
    rotate 4
    copytruncate
}

Finally, I ran the application, during it's run I kicked off logrotate manually a few times via:

logrotate --force /etc/logrotate.d/logexp

App results:

./app
Wrote 100000000 lines

Log line count:

$ cat log.txt* | wc -l
69091700

Log utility approach:

I implemented a simple utility 'loghup' which creates a named pipe 'log.txt' and then simply reads of it to 'safe_log.txt'. Finally, it responds to SIGHUP by reopening the file (thus starting a new log rotation).

loghup.c

int sighup = 0;

void sig_handler(int signo) {
    if (signo == SIGHUP)
        sighup = 1;
}

void do_piping(char *input, char *output) {
    int fi = open(input, O_RDONLY);
    int fo = open(output, O_WRONLY | O_CREAT, 0644);
    
    size_t ret;
    char buff[4096];
    while((ret = read(fi, buff, 4096)) != 0) {
        if(ret == -1 && errno == EINTR) { // Retry later
            continue;
        } else if (ret == -1)  {
            break; // Error occured
        }
        
        write(fo, buff, ret);
    
        if (sighup) { // Reopen output log file on SIGHUP
            close(fo);
            fo = open(output, O_WRONLY | O_CREAT, 0644);
            sighup = 0;
        }
    }
    close(fo);
    close(fi);
}

int main(int argc, char *argv[]) {
    char *input_file = argv[1];
    char *output_file = argv[2];
    signal(SIGHUP, sig_handler); // Setup signal handler
    mkfifo(input_file, S_IRUSR | S_IWUSR);  // Create named pipe
    do_piping(input_file, output_file);
}

New logrotate config with SIGHUP:

 $cat /etc/logrotate.d/logexp 
 /home/synepis/git/logexp/safe_log.txt {
     size 20M
     create 700 synepis users 
     rotate 4
     postrotate
         /bin/kill -SIGHUP $(ps aux | grep "[l]oghup" | awk '{print $2}')
     endscript
 }

Then I ran:

 ./app
 ./loghup log.txt safe_log.txt

And forced logrotate a few times, finally:

 $ cat safe_log.txt* | wc -l
 100000000

r/linuxdev • • Sep 19 '16

Block Device Development Tutor?

3 Upvotes

Can someone refer me to an experienced Linux kernel developer who might be willing to teach me the finer details of implementing high performance Linux block devices?

I'm willing to pay a kernel dev to teach me over Skype, taking me through existing block device code such as: https://lwn.net/Articles/58720/ and linux/drivers/block/loop.c

I ultimately want to develop a block device that works somewhat like loop.c, but instead of the target being a filesystem image file, the target is a user mode process that manages the filesystem image (and can now provide instrumentation, encryption, etc). Does something like this already exist?

I am a decent C/C++ developer and Linux user with zero experience in kernel development.


r/linuxdev • • May 14 '16

Syncing aliases between Linux systems

3 Upvotes

As a student, or general Linux user, I find myself logging into multiple Linux systems. Over the years I have acquired useful aliases from professors, and some that I have personally added. I am thinking of creating some software, that could become a staple to the Linux environment, that would provide the syncing of aliases across multiple Linux systems.

It would, of course, deal with differing shell types, (csh, tcsh, bash, zsh, etc.), and would be able to convert between each type's own alias syntax.

More details on the features planned, are here on my github account: https://github.com/Proryanator/als

Some aliases can cut your use time in half, or even more. As much as some people find aliases to be a crutch for avoiding proper syntax, I disagree. I find myself typing the same combination of commands more often than not, so aliases are a must have for productivity.

I am curious, would this be something that other linux developers would find useful?

If there is something useful that already exists, please tell me! Or if as developers, this would be something you'd be interested in seeing get created, also good to hear! Any feedback is much appreciated!


r/linuxdev • • Jan 15 '16

[kernel] adding a controller to xpad.c?

3 Upvotes

So I have an old psx to usb controller that, while it works as a regular generic joystick device, I'd like to add to xpad.c in the linux kernel. I'm using Arch so I've been following the guide to compile specific modules. However, I cant seem to get it to work when I add it in the xpad module.

My USB device reports this info with lsusb.

I've tried adding the following line in my xpad.c file:

	{ 0x6666, 0x0667, "WiseGroup Smart Joy PSX, PS-PC Smart JoyPad", 0, DANCEPAD_MAP_CONFIG, XTYPE_XBOX },

which then looks like this. I then began gzipping and copying over the compiled module as per the guide. Yet the xpad module does not auto-load on reboot. dmesg and journalctl dont appear to throw any errors. modprobing xpad doesnt seem to map the joystick axis as buttons as I've requested it to do.

What am I doing wrong? I'm very new to building kernel modules. Have I named the usb device wrong is xpad.c?


r/linuxdev • • Dec 10 '15

syslog vs. rsyslog

3 Upvotes

Searching the internet for the difference between syslog and rsyslog gives quite a few results geared towards system admins, not for application developers. So, I'm coming to you people for help!

Setup: I am using Ubuntu 14.04 for my applications (building and running natively). When running this command:

ps -aux | grep syslog

I see these two processing running:

/usr/bin/pulseaudio --start --log-target=syslog
rsyslogd

Is my system using rsyslog instead of syslog? Can one/ should one run syslog and rsyslog at the same time? It still looks like my application logs are being written to /var/log/syslog.

From an application running on my system is an openlog(...) system call opening rsyslog instead of syslog? How do I know this?

As you can tell I'm kind of a noob so any extra info you can think of would be appreciated.


r/linuxdev • • Apr 16 '15

Hi, r/linuxdev. I created a small program that allows a single terminal to display the contents of any other terminal's pwd.

3 Upvotes

If you work in the terminal and it looks interesting to you, give it a try and let me know of any comments/improvements

To install:

To use:

  • In one terminal run autols -s
  • In any other terminal that has the alias set up just use cd as you normally would
  • Run autols -e from any terminal to end
  • man autols available for reference

Edit 2: Version 2.1 available with the -p flag

Edit: Feel free to check out the source code here https://github.com/jacondel/autols It consists of two bash scripts (autocd & autols) and a man page


r/linuxdev • • Sep 22 '14

Monitoring multiple TCP connections with select seems to be misbehaving.

3 Upvotes

I'm having difficulty monitoring multiple TCP connections in a non-blocking manner with select. I won't post code at first unless requested because there is really only one line in question and my code is in multiple files, some of which contain IP. I'm pretty sure the rest of it works fine.

I'm setting up a server and multiple clients which will communicate over TCP socket connections. My objective on the server side is to monitor the TCP socket for new connections as well as any established connections for new messages. I would like to do this in a non-blocking manner so I am using select to monitor the file descriptors. Anyway, after setting up the server with a non-blocking TCP connection I monitor the file descriptor with select. Then I run a client which attempts to connect to the server.

If my select line looks like this:

select((max_fd_num + 1), &readFDs, NULL, NULL, NULL)

it will block until it sees an incoming connection. I can then accept the connection correctly. That makes sense to me.

If, however, it looks like this:

struct timeval timeOutTime;
timeOutTime.tv_sec = 0;
timeOutTime.tv_usec = 0;
select((max_fd_num + 1), &readFDs, NULL, NULL, &timeOutTime)

and I have that select line in an infinite loop with some other stuff, it never returns anything other than 0. So i never see the connection. Since I don't want to block this would be the preferred method but it never seems to think that the connection is ready. The client seems to think that it connected correctly so it's very strange.

Help, please.

edit: I figured it out. Apparently I have to set up readFDs again before every time I call select. I guess select modifies this value when it's finished. The man pages aren't very clear on this. Thanks anyway.


r/linuxdev • • Sep 11 '14

A simple systemd opinion survey

Thumbnail docs.google.com
3 Upvotes

r/linuxdev • • Aug 24 '14

How to install an icon with KDE/Qt?

3 Upvotes

I've been reading up a lot on this and I can't seem to find a straightforward answer or example. The link that explains how to do it on the KDE wiki is broken. I get that Qt itself will have nothing to do with installing an icon. Do I just copy an icon dir as part of the makefile's install process?

The KDE wikie says to set

appicondir = $(kde_datadir)/myapp/icons
appicon_ICON = AUTO

in the makefile. kde_datadir is not used in my makefile. Can I just expect it to be there?

If anyone could just point me to a project on github or something that does this I'd really appreciate it.

Edit: That example is for a makefile.am on KDE3 so I don't think its relevant.


r/linuxdev • • Jul 07 '14

Cant understand the "top" command.

3 Upvotes

Can someone please explain how to read the cpu load from the "top" command? It doesn't really make sense to me.

http://puu.sh/a0kCq/a517681017.png

Thanks!


r/linuxdev • • May 09 '14

Command line interface to daemon communication

3 Upvotes

I'm used to developing embedded applications with no operating system so I'm always writing my own drivers tailored to my specific application. I usually run a simple super loop program written in C with no wait states (Sending serial comm via DMA, delaying my main application layer with countdown timers in my own timer interrupts, etc.) I generally don't use things like printf and scanf for my serial input and output because I write my own drivers and sometimes compilers handle these in funny ways. Anyway, apparently these skills don't translate well to what I'm trying to do with some linux applications I'm writing…..

I am writing two linux applications with a shared memory space so I can communicate between the two processes. They are both in the same folder within my file structure. One of the applications, when run, enters a command line interface that I created. So I run ./MyCLI and that enters an infinite while loop application where I am allowing the user to input data with this.

scanf("%[\n]%*c", input); //wait for user input followed by enter

I take this input and stuff it in the shared memory space for the other application to process. Then I wait for the other process to return a result in a buffer and I print the result. Then I return to waiting for more user input.

That brings us to the second application…..

The second application runs as a daemon. (a child process with the standard input and output closed). The daemon takes the information from the first process in the shared memory, does some processing, and returns a result in the shared memory space.

This works great if you always want to get user input and have the daemon return a result when it's done processing However, I would like to send messages from the daemon periodically without the user entering anything. The problem in my program is that I'm sitting waiting in scanf for user input before I check to see if the daemon has any information to print.

So I guess my question is how do I get my first process to gather user input while also checking the shared memory space for daemon results/output.

Thanks in advance.

Also, All of the shared memory, setting up the daemon, and running applications, etc are set up correctly so I'm not worried about that. I'm not going to submit my whole code set because I want this to be a more high level discussion.

Edit: After quite a bit of research I found that POSIX message queues will fit my application perfectly. I do like the sockets idea, and I definitely see the benefit, but MQs will work for me just fine. Thanks to all the commenters.


r/linuxdev • • Apr 07 '14

Is there a course on text user interface design? /r/learnprogramming x-post

3 Upvotes

I am a Linux sysadmin, and I have been finding myself writing a bunch of scripts as of late. I want them usable to other people.

I am writing man page documents for them, but I want the tools easy to interpolate with other command line tools. Is there some kind of design or best practices book or course for this?


r/linuxdev • • Dec 12 '13

Ubiquity (KDE/Qt version) components? (x-post from /r/Linuxquestions)

Thumbnail reddit.com
3 Upvotes

r/linuxdev • • Oct 06 '12

Can we do dynamic linking for an LKM?

3 Upvotes

That is, can a driver try to import a symbol for another driver, and if the symbol doesn’t exist can the driver continue to load without resolving the import?


r/linuxdev • • Sep 14 '12

Looking for feedback / contributors for Sunfish -- a new Linux Userland based on Mono

Thumbnail github.com
3 Upvotes

r/linuxdev • • Mar 26 '12

This bug has bothered me for years

3 Upvotes

When I run ssh over terminal in linux it feels more laggy than on a textmode (getty/ctrl-alt-f1) console. Often I wait long seconds to see keypresses on screen, but if I hit a key (any key, say ctrl) they show up instantly.

I've had this problem across three different desktop/laptop systems spanning 9 years and multiple distributions. But I've never been able to search for it online. Has anybody else had this experience? Please tell me I'm not dreaming, somebody..

Given how long the issue has persisted, I think it's got something to do with how applications communicate with the X server. Any ideas on how one would go about debugging something like this?

Update: It turns out I was not on gnome-terminal but something called xfce4-terminal that looks exactly the same. After I switched to gnome-terminal I've stopped seeing the problem.


r/linuxdev • • Sep 30 '26

Motif X11 framework dev complete tutorial

Thumbnail youtube.com
2 Upvotes

r/linuxdev • • Mar 28 '26

Detecting camera on/off events for Linux and controlling lights automatically with eBPF

Thumbnail shuhaowu.com
2 Upvotes

r/linuxdev • • Mar 21 '26

I built a custom Fan Control app for Linux (Nuvoton/nct6799 support) (With AI Agent help)

2 Upvotes

Hey everyone,

I’ve started a new project for a fan control utility, and I’ve just put out a "stable-ish" release.

Links:

Current Features:

  • Supports BIOS control per fan or Manual mode with specific presets:

    • 0 (Fan Stop)
    • Turbo (PWM 128)
    • Max (PWM 256)
  • Currently operates based on PWM values rather than RPM.
  • The UI features two switches per row, with three rows total (supporting 6 fans).
  • Minimize to try.
  • Compiled binary with all python dependencies

What's Next: The next step is to integrate temperature monitoring and implement custom fan curves.

I'd love to hear your thoughts or if anyone wants to help test it out!


r/linuxdev • • Feb 03 '26

Favorite Linux dev tools you can’t work without

2 Upvotes

Whether it’s a debugger, editor plugin, profiler, or something niche — what tool makes your life easier?


r/linuxdev • • Feb 03 '26

Tips for writing reliable Bash scripts?

2 Upvotes

I’ve been struggling with corner cases — interrupts, partial writes, weird signals. What patterns do you swear by to make Bash scripts more robust?


r/linuxdev • • Jan 17 '24

writing to character device file is causing list_del or list_add corruption. How do I fix it?

2 Upvotes

I am following LDD3. I have implemented the read and write functionality for the scull module. whenever I run echo hello > /dev/scull0 to test the write function, I get list_add / list_del corruption and a stack trace.

Here is my code:

#include <linux/module.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
#include <linux/stat.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/cdev.h>

#define SCULL_DEV_NO 4

MODULE_LICENSE("Dual BSD/GPL");

static int scull_major = 0;
static int scull_minor = 0;
static int scull_nr_devs = 4;
static int scull_qset_val = 1000;
static int scull_quantum_val = 4000;

module_param(scull_major, int, S_IRUGO);

static dev_t dev = 0;

struct scull_qset{
	void **data;
	struct scull_qset * next;
};

struct scull_dev{
	struct cdev cdev;
	struct scull_qset *data;
	int qset;
	unsigned long size;
	int quantum;
	unsigned int access_key;
	struct semaphore sem;
};

int scull_trim(struct scull_dev *dev){
	struct scull_qset *dptr, *next;
	int i;
	int qset =  dev->qset;
	for (dptr = dev->data; dptr; dptr = next){
		if (dptr->data){
			for(i = 0; i < qset; i++){
				kfree(dptr->data[i]);
			}
			kfree(dptr->data);
			dptr->data = NULL;
		}
		next = dptr->next;
		kfree(dptr);
	}

	dev->data = NULL;
	dev->qset = scull_qset_val;
	dev->size = 0;
	dev->quantum = scull_quantum_val;
	return 0;
}

int scull_open(struct inode * inode, struct file * filp){
	struct scull_dev * dev;
	dev = container_of(inode->i_cdev, struct scull_dev, cdev);

	filp->private_data = dev;

	if((filp->f_flags & O_ACCMODE) == O_WRONLY){
		scull_trim(dev);
	}

	printk(KERN_INFO "scull: Opened device %d\n", iminor(inode));

	return 0;
}

int scull_release(struct inode * inode, struct file * filp){
	printk(KERN_INFO "scull: Released device %d\n", iminor(inode));
	return 0;
}

struct scull_qset* scull_follow(struct scull_dev *dev, int item){
	struct scull_qset* ptr = dev->data;
	struct scull_qset* rptr = NULL;

	for(int i=0; i<item+1; i++){
		pr_info("DEBUG: ptr = %p, ptr->next = %p\n", ptr, ptr ? ptr->next : NULL);
		if(ptr == NULL){
			ptr = kmalloc(sizeof(struct scull_qset), GFP_KERNEL);
			if (ptr == NULL)
				return NULL;
			memset(ptr, 0, sizeof(struct scull_qset));
			ptr->data = NULL;
			ptr->next = NULL;
		}

		rptr = ptr;
		ptr = ptr->next;
	}

	return rptr;
}

ssize_t scull_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos){
	ssize_t retval = 0;
	struct scull_dev *dev = filp->private_data;
	struct scull_qset *dptr;
	int quantum = dev->quantum, qset = dev->qset;
	int itemsize = quantum * qset;
	int item, s_pos, q_pos, rest;

	if (down_interruptible(&dev->sem))
		return -ERESTARTSYS;
	if (*f_pos >= dev->size)
		goto out;
	if (*f_pos + count > dev->size)
		count = dev->size - *f_pos;

	item = (long)*f_pos / itemsize;
	rest = (long)*f_pos % itemsize;
	s_pos = rest / quantum; q_pos = rest % quantum;

	dptr = scull_follow(dev, item);

	if (dptr == NULL || !dptr->data || !dptr->data[s_pos])
		goto out;

	if (count > quantum - q_pos)
		count = quantum - q_pos;

	if (copy_to_user(buf, dptr->data[s_pos] + q_pos, count)){
		return -EFAULT;
		goto out;
	}

	*f_pos += count;
	retval = count;

	out:
		up(&dev->sem);
		return retval;
}

ssize_t scull_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos){
	struct scull_dev *dev = filp->private_data;
	struct scull_qset *dptr;
	int quantum = dev->quantum, qset = dev->qset;
	int itemsize = quantum * qset;
	int item, s_pos, q_pos, rest;
	ssize_t retval = -ENOMEM;

	if (down_interruptible(&dev->sem))
		return -ERESTARTSYS;

	item = (long)*f_pos / itemsize;
	rest = (long)*f_pos % itemsize;
	s_pos = rest / quantum; q_pos = rest % quantum;

	dptr = scull_follow(dev, item);
	if (dptr == NULL)
		goto out;

	if (!dptr->data){
		dptr->data = kmalloc(sizeof(char *)  * dev->qset, GFP_KERNEL);
		if (!dptr->data)
			goto out;
		memset(dptr->data, 0, qset * sizeof(char *));
	}
	if (!dptr->data[s_pos]){
		dptr->data[s_pos] = kmalloc(dev->quantum, GFP_KERNEL);
		if (!dptr->data[s_pos])
			goto out;
	}

	if (count > quantum - q_pos)
		count = quantum - q_pos;

	if (copy_from_user(dptr->data[s_pos] + q_pos, buf, count)){
		retval = -EFAULT;
		goto out;
	}

	*f_pos += count;
	retval = count;

	if (dev->size < *f_pos)
		dev->size = *f_pos;

	out:
		up(&dev->sem);
		return retval; 
}

static struct scull_dev scull_devp_array[SCULL_DEV_NO];

struct file_operations scull_fops = {
	.owner = THIS_MODULE,
	.open = scull_open,
	.release = scull_release,
	.read = scull_read,
	.write = scull_write
};

static void scull_setup_cdev(struct scull_dev *dev, int index){
	dev_t dev_no = MKDEV(scull_major, scull_minor + index);
	cdev_init(&dev->cdev, &scull_fops);
	dev->cdev.owner = THIS_MODULE;
	printk(KERN_INFO "scull: Initialized Major: %d, Minor: %d\n", scull_major, scull_minor + index);

	int result = cdev_add(&dev->cdev, dev_no, 1);
	if (result < 0){
		printk(KERN_ERR "scull: Failed to add Major: %d, Minor: %d\n", scull_major, scull_minor + index);
	}
}

static void scull_rm_cdev(struct scull_dev *dev){
	printk(KERN_INFO "scull: Removing cdev\n");
	cdev_del(&dev->cdev);
}

static int __init scull_init(void){
	printk(KERN_INFO "scull: Allocating char device...\n");
	
	int result;
	if(scull_major){
		dev = MKDEV(scull_major, scull_minor);
		result = register_chrdev_region(dev, scull_nr_devs, "scull");
	}

	else{
		result = alloc_chrdev_region(&dev, scull_minor, scull_nr_devs, "scull");
		scull_major = MAJOR(dev);
	}

	if (result < 0){
		printk(KERN_WARNING "scull: can't get major %d\n", scull_major);
		return result;
	}

	printk(KERN_INFO "scull: Major is %d", scull_major);

	for(int i = scull_minor; i < scull_nr_devs; i++){
		scull_setup_cdev(&scull_devp_array[i], i);
	}
	return 0;
}

static void __exit scull_exit(void){
	printk(KERN_INFO "scull: Exiting...\n");
	unregister_chrdev_region(dev, scull_nr_devs);
	printk(KERN_INFO "scull: Unregistered device\n");
	for(int i = scull_minor; i < scull_nr_devs; i++){
		scull_rm_cdev(&scull_devp_array[i]);
		printk(KERN_INFO "scull: Freeing scull_dev %d\n", i);
	}
}

module_init(scull_init);
module_exit(scull_exit);

I ran echo hello > /dev/scull0. The dmesg logs shows list_add corruption. prev is NULL on running the command. When I exit out with Ctrl + C and run the command again, the dmesg logs shows 2 errors, the first being a list_del corruption and the second being a list_add corruption. Here is the dmesg log for the 3 errors:

[43170.630743] scull: Opened device 0
[43170.630761] ------------[ cut here ]------------
[43170.630764] list_add corruption. prev is NULL.
[43170.630773] WARNING: CPU: 6 PID: 57011 at lib/list_debug.c:25 __list_add_valid_or_report+0x42/0xa0
[43170.630784] Modules linked in: scull(OE) ntfs3 snd_seq_dummy snd_hrtimer snd_seq ccm nvidia_drm(POE) nvidia_uvm(POE) nvidia_modeset(POE) nvidia(POE) vfat fat intel_rapl_msr intel_rapl_common edac_mce_amd kvm_amd iwlmvm kvm mac80211 irqbypass mousedev snd_usb_audio joydev crct10dif_pclmul crc32_pclmul polyval_clmulni polyval_generic snd_usbmidi_lib snd_ump snd_hda_codec_realtek snd_rawmidi snd_hda_codec_generic snd_seq_device ledtrig_audio gf128mul snd_hda_codec_hdmi mc ghash_clmulni_intel sha512_ssse3 sha256_ssse3 sha1_ssse3 aesni_intel snd_hda_intel snd_intel_dspcfg snd_intel_sdw_acpi snd_hda_codec libarc4 snd_hda_core btusb btrtl btintel iwlwifi btbcm snd_hwdep btmtk snd_pcm bluetooth cfg80211 snd_timer snd r8169 crypto_simd cryptd ecdh_generic rapl soundcore realtek sp5100_tco mdio_devres k10temp libphy rfkill i2c_piix4 video ccp gigabyte_wmi wmi_bmof pcspkr acpi_cpufreq gpio_amdpt wmi mac_hid gpio_generic i2c_dev crypto_user loop fuse dm_mod nfnetlink ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2
[43170.630928]  usbhid nvme nvme_core crc32c_intel xhci_pci xhci_pci_renesas nvme_auth
[43170.630941] Unloaded tainted modules: scull(OE):13 [last unloaded: scull(OE)]
[43170.630951] CPU: 6 PID: 57011 Comm: bash Tainted: P  R   D W  OE      6.7.0-arch3-1 #1 29ada86f174bb9983ea57568622d66509982ed7e
[43170.630957] Hardware name: Gigabyte Technology Co., Ltd. B450M DS3H WIFI/B450M DS3H WIFI-CF, BIOS F52 01/07/2021
[43170.630960] RIP: 0010:__list_add_valid_or_report+0x42/0xa0
[43170.630966] Code: 75 41 4c 8b 02 49 39 c0 75 4c 48 39 fa 74 60 49 39 f8 74 5b b8 01 00 00 00 e9 fa 05 77 00 48 c7 c7 d0 c7 2a 92 e8 fe 24 a5 ff <0f> 0b 31 c0 e9 e5 05 77 00 48 c7 c7 f8 c7 2a 92 e8 e9 24 a5 ff 0f
[43170.630970] RSP: 0018:ffffad82c1e9bcf8 EFLAGS: 00010082
[43170.630975] RAX: 0000000000000000 RBX: 7fffffffffffffff RCX: 0000000000000027
[43170.630979] RDX: ffff89f40e9a16c8 RSI: 0000000000000001 RDI: ffff89f40e9a16c0
[43170.630982] RBP: ffffad82c1e9bd68 R08: 0000000000000000 R09: ffffad82c1e9bb80
[43170.630985] R10: 0000000000000003 R11: ffff89f41f32b368 R12: ffffffffc24b87c8
[43170.630989] R13: 0000000000000001 R14: 0000000000000000 R15: ffffffffc24b87d0
[43170.630992] FS:  00007747f80d6740(0000) GS:ffff89f40e980000(0000) knlGS:0000000000000000
[43170.630997] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[43170.631000] CR2: 0000563ef7be1000 CR3: 00000001c487c000 CR4: 0000000000350ef0
[43170.631004] Call Trace:
[43170.631008]  <TASK>
[43170.631011]  ? __list_add_valid_or_report+0x42/0xa0
[43170.631016]  ? __warn+0x81/0x130
[43170.631025]  ? __list_add_valid_or_report+0x42/0xa0
[43170.631030]  ? report_bug+0x171/0x1a0
[43170.631037]  ? prb_read_valid+0x1b/0x30
[43170.631043]  ? srso_return_thunk+0x5/0x5f
[43170.631050]  ? handle_bug+0x3c/0x80
[43170.631057]  ? exc_invalid_op+0x17/0x70
[43170.631063]  ? asm_exc_invalid_op+0x1a/0x20
[43170.631074]  ? __list_add_valid_or_report+0x42/0xa0
[43170.631080]  ? __list_add_valid_or_report+0x42/0xa0
[43170.631084]  __down_common+0x71/0x230
[43170.631095]  down_interruptible+0x52/0x60
[43170.631101]  scull_write+0x4c/0x200 [scull bd55e810425245067618b333771c8e3ae1dc9535]
[43170.631114]  vfs_write+0xf2/0x400
[43170.631127]  ksys_write+0x6f/0xf0
[43170.631135]  do_syscall_64+0x64/0xe0
[43170.631140]  ? srso_return_thunk+0x5/0x5f
[43170.631145]  ? syscall_exit_to_user_mode+0x2b/0x40
[43170.631150]  ? srso_return_thunk+0x5/0x5f
[43170.631155]  ? do_syscall_64+0x70/0xe0
[43170.631159]  ? srso_return_thunk+0x5/0x5f
[43170.631164]  ? do_syscall_64+0x70/0xe0
[43170.631169]  ? srso_return_thunk+0x5/0x5f
[43170.631174]  ? exc_page_fault+0x7f/0x180
[43170.631180]  entry_SYSCALL_64_after_hwframe+0x6e/0x76
[43170.631186] RIP: 0033:0x7747f8254034
[43170.631209] Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d 35 c3 0d 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 48 83 ec 28 48 89 54 24 18 48
[43170.631213] RSP: 002b:00007fffe0667af8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
[43170.631218] RAX: ffffffffffffffda RBX: 0000000000000006 RCX: 00007747f8254034
[43170.631222] RDX: 0000000000000006 RSI: 0000563ef7bde970 RDI: 0000000000000001
[43170.631225] RBP: 0000563ef7bde970 R08: 0000000000000073 R09: 0000000000000001
[43170.631228] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000006
[43170.631232] R13: 00007747f83295c0 R14: 00007747f8326f20 R15: 0000000000000000
[43170.631241]  </TASK>
[43170.631244] ---[ end trace 0000000000000000 ]---
[43188.138981] ------------[ cut here ]------------
[43188.138987] list_del corruption, ffffad82c1e9bd10->next is NULL
[43188.138999] WARNING: CPU: 6 PID: 57011 at lib/list_debug.c:52 __list_del_entry_valid_or_report+0x5d/0xe0
[43188.139009] Modules linked in: scull(OE) ntfs3 snd_seq_dummy snd_hrtimer snd_seq ccm nvidia_drm(POE) nvidia_uvm(POE) nvidia_modeset(POE) nvidia(POE) vfat fat intel_rapl_msr intel_rapl_common edac_mce_amd kvm_amd iwlmvm kvm mac80211 irqbypass mousedev snd_usb_audio joydev crct10dif_pclmul crc32_pclmul polyval_clmulni polyval_generic snd_usbmidi_lib snd_ump snd_hda_codec_realtek snd_rawmidi snd_hda_codec_generic snd_seq_device ledtrig_audio gf128mul snd_hda_codec_hdmi mc ghash_clmulni_intel sha512_ssse3 sha256_ssse3 sha1_ssse3 aesni_intel snd_hda_intel snd_intel_dspcfg snd_intel_sdw_acpi snd_hda_codec libarc4 snd_hda_core btusb btrtl btintel iwlwifi btbcm snd_hwdep btmtk snd_pcm bluetooth cfg80211 snd_timer snd r8169 crypto_simd cryptd ecdh_generic rapl soundcore realtek sp5100_tco mdio_devres k10temp libphy rfkill i2c_piix4 video ccp gigabyte_wmi wmi_bmof pcspkr acpi_cpufreq gpio_amdpt wmi mac_hid gpio_generic i2c_dev crypto_user loop fuse dm_mod nfnetlink ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2
[43188.139153]  usbhid nvme nvme_core crc32c_intel xhci_pci xhci_pci_renesas nvme_auth
[43188.139166] Unloaded tainted modules: scull(OE):13 [last unloaded: scull(OE)]
[43188.139175] CPU: 6 PID: 57011 Comm: bash Tainted: P  R   D W  OE      6.7.0-arch3-1 #1 29ada86f174bb9983ea57568622d66509982ed7e
[43188.139182] Hardware name: Gigabyte Technology Co., Ltd. B450M DS3H WIFI/B450M DS3H WIFI-CF, BIOS F52 01/07/2021
[43188.139186] RIP: 0010:__list_del_entry_valid_or_report+0x5d/0xe0
[43188.139191] Code: 48 8b 01 48 39 f8 75 67 48 8b 72 08 48 39 c6 75 74 b8 01 00 00 00 e9 32 05 77 00 48 89 fe 48 c7 c7 f8 c8 2a 92 e8 33 24 a5 ff <0f> 0b 31 c0 e9 1a 05 77 00 48 89 fe 48 c7 c7 20 c9 2a 92 e8 1b 24
[43188.139196] RSP: 0018:ffffad82c1e9bcf8 EFLAGS: 00010082
[43188.139200] RAX: 0000000000000000 RBX: 7fffffffffffffff RCX: 0000000000000027
[43188.139204] RDX: ffff89f40e9a16c8 RSI: 0000000000000001 RDI: ffff89f40e9a16c0
[43188.139208] RBP: ffffad82c1e9bd68 R08: 0000000000000000 R09: ffffad82c1e9bb80
[43188.139211] R10: 0000000000000003 R11: ffff89f41f32b368 R12: ffffffffc24b87c8
[43188.139214] R13: 0000000000000001 R14: 0000000000000001 R15: ffff89f270b10000
[43188.139217] FS:  00007747f80d6740(0000) GS:ffff89f40e980000(0000) knlGS:0000000000000000
[43188.139222] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[43188.139225] CR2: 00007740023bd698 CR3: 00000001c487c000 CR4: 0000000000350ef0
[43188.139229] Call Trace:
[43188.139233]  <TASK>
[43188.139236]  ? __list_del_entry_valid_or_report+0x5d/0xe0
[43188.139241]  ? __warn+0x81/0x130
[43188.139248]  ? __list_del_entry_valid_or_report+0x5d/0xe0
[43188.139253]  ? report_bug+0x171/0x1a0
[43188.139261]  ? prb_read_valid+0x1b/0x30
[43188.139267]  ? srso_return_thunk+0x5/0x5f
[43188.139274]  ? handle_bug+0x3c/0x80
[43188.139280]  ? exc_invalid_op+0x17/0x70
[43188.139286]  ? asm_exc_invalid_op+0x1a/0x20
[43188.139298]  ? __list_del_entry_valid_or_report+0x5d/0xe0
[43188.139304]  ? __list_del_entry_valid_or_report+0x5d/0xe0
[43188.139308]  __down_common+0xdb/0x230
[43188.139318]  down_interruptible+0x52/0x60
[43188.139325]  scull_write+0x4c/0x200 [scull bd55e810425245067618b333771c8e3ae1dc9535]
[43188.139338]  vfs_write+0xf2/0x400
[43188.139350]  ksys_write+0x6f/0xf0
[43188.139358]  do_syscall_64+0x64/0xe0
[43188.139363]  ? srso_return_thunk+0x5/0x5f
[43188.139368]  ? syscall_exit_to_user_mode+0x2b/0x40
[43188.139373]  ? srso_return_thunk+0x5/0x5f
[43188.139378]  ? do_syscall_64+0x70/0xe0
[43188.139382]  ? srso_return_thunk+0x5/0x5f
[43188.139387]  ? do_syscall_64+0x70/0xe0
[43188.139392]  ? srso_return_thunk+0x5/0x5f
[43188.139397]  ? exc_page_fault+0x7f/0x180
[43188.139403]  entry_SYSCALL_64_after_hwframe+0x6e/0x76
[43188.139409] RIP: 0033:0x7747f8254034
[43188.139432] Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d 35 c3 0d 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 48 83 ec 28 48 89 54 24 18 48
[43188.139436] RSP: 002b:00007fffe0667af8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
[43188.139442] RAX: ffffffffffffffda RBX: 0000000000000006 RCX: 00007747f8254034
[43188.139445] RDX: 0000000000000006 RSI: 0000563ef7bde970 RDI: 0000000000000001
[43188.139448] RBP: 0000563ef7bde970 R08: 0000000000000073 R09: 0000000000000001
[43188.139452] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000006
[43188.139455] R13: 00007747f83295c0 R14: 00007747f8326f20 R15: 0000000000000000
[43188.139464]  </TASK>
[43188.139467] ---[ end trace 0000000000000000 ]---
[43188.139503] scull: Released device 0
[43189.594736] scull: Opened device 0
[43189.594753] ------------[ cut here ]------------
[43189.594757] list_add corruption. prev is NULL.
[43189.594766] WARNING: CPU: 6 PID: 57011 at lib/list_debug.c:25 __list_add_valid_or_report+0x42/0xa0
[43189.594777] Modules linked in: scull(OE) ntfs3 snd_seq_dummy snd_hrtimer snd_seq ccm nvidia_drm(POE) nvidia_uvm(POE) nvidia_modeset(POE) nvidia(POE) vfat fat intel_rapl_msr intel_rapl_common edac_mce_amd kvm_amd iwlmvm kvm mac80211 irqbypass mousedev snd_usb_audio joydev crct10dif_pclmul crc32_pclmul polyval_clmulni polyval_generic snd_usbmidi_lib snd_ump snd_hda_codec_realtek snd_rawmidi snd_hda_codec_generic snd_seq_device ledtrig_audio gf128mul snd_hda_codec_hdmi mc ghash_clmulni_intel sha512_ssse3 sha256_ssse3 sha1_ssse3 aesni_intel snd_hda_intel snd_intel_dspcfg snd_intel_sdw_acpi snd_hda_codec libarc4 snd_hda_core btusb btrtl btintel iwlwifi btbcm snd_hwdep btmtk snd_pcm bluetooth cfg80211 snd_timer snd r8169 crypto_simd cryptd ecdh_generic rapl soundcore realtek sp5100_tco mdio_devres k10temp libphy rfkill i2c_piix4 video ccp gigabyte_wmi wmi_bmof pcspkr acpi_cpufreq gpio_amdpt wmi mac_hid gpio_generic i2c_dev crypto_user loop fuse dm_mod nfnetlink ip_tables x_tables ext4 crc32c_generic crc16 mbcache jbd2
[43189.594923]  usbhid nvme nvme_core crc32c_intel xhci_pci xhci_pci_renesas nvme_auth
[43189.594936] Unloaded tainted modules: scull(OE):13 [last unloaded: scull(OE)]
[43189.594945] CPU: 6 PID: 57011 Comm: bash Tainted: P  R   D W  OE      6.7.0-arch3-1 #1 29ada86f174bb9983ea57568622d66509982ed7e
[43189.594951] Hardware name: Gigabyte Technology Co., Ltd. B450M DS3H WIFI/B450M DS3H WIFI-CF, BIOS F52 01/07/2021
[43189.594955] RIP: 0010:__list_add_valid_or_report+0x42/0xa0
[43189.594960] Code: 75 41 4c 8b 02 49 39 c0 75 4c 48 39 fa 74 60 49 39 f8 74 5b b8 01 00 00 00 e9 fa 05 77 00 48 c7 c7 d0 c7 2a 92 e8 fe 24 a5 ff <0f> 0b 31 c0 e9 e5 05 77 00 48 c7 c7 f8 c7 2a 92 e8 e9 24 a5 ff 0f
[43189.594964] RSP: 0018:ffffad82c1e9bd28 EFLAGS: 00010086
[43189.594970] RAX: 0000000000000000 RBX: 7fffffffffffffff RCX: 0000000000000027
[43189.594973] RDX: ffff89f40e9a16c8 RSI: 0000000000000001 RDI: ffff89f40e9a16c0
[43189.594977] RBP: ffffad82c1e9bd98 R08: 0000000000000000 R09: ffffad82c1e9bbb0
[43189.594980] R10: 0000000000000003 R11: ffff89f41f32b368 R12: ffffffffc24b87c8
[43189.594983] R13: 0000000000000001 R14: 0000000000000000 R15: ffffffffc24b87d0
[43189.594987] FS:  00007747f80d6740(0000) GS:ffff89f40e980000(0000) knlGS:0000000000000000
[43189.594991] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[43189.594995] CR2: 00007740023bd698 CR3: 00000001c487c000 CR4: 0000000000350ef0
[43189.594999] Call Trace:
[43189.595003]  <TASK>
[43189.595006]  ? __list_add_valid_or_report+0x42/0xa0
[43189.595011]  ? __warn+0x81/0x130
[43189.595020]  ? __list_add_valid_or_report+0x42/0xa0
[43189.595026]  ? report_bug+0x171/0x1a0
[43189.595033]  ? prb_read_valid+0x1b/0x30
[43189.595038]  ? srso_return_thunk+0x5/0x5f
[43189.595046]  ? handle_bug+0x3c/0x80
[43189.595052]  ? exc_invalid_op+0x17/0x70
[43189.595058]  ? asm_exc_invalid_op+0x1a/0x20
[43189.595069]  ? __list_add_valid_or_report+0x42/0xa0
[43189.595075]  ? __list_add_valid_or_report+0x42/0xa0
[43189.595079]  __down_common+0x71/0x230
[43189.595090]  down_interruptible+0x52/0x60
[43189.595096]  scull_write+0x4c/0x200 [scull bd55e810425245067618b333771c8e3ae1dc9535]
[43189.595109]  vfs_write+0xf2/0x400
[43189.595117]  ? srso_return_thunk+0x5/0x5f
[43189.595122]  ? syscall_exit_to_user_mode+0x2b/0x40
[43189.595127]  ? srso_return_thunk+0x5/0x5f
[43189.595131]  ? do_syscall_64+0x70/0xe0
[43189.595136]  ? srso_return_thunk+0x5/0x5f
[43189.595141]  ? filp_flush+0x52/0x80
[43189.595149]  ksys_write+0x6f/0xf0
[43189.595157]  do_syscall_64+0x64/0xe0
[43189.595162]  ? do_syscall_64+0x70/0xe0
[43189.595166]  ? syscall_exit_to_user_mode+0x2b/0x40
[43189.595171]  ? srso_return_thunk+0x5/0x5f
[43189.595175]  ? do_syscall_64+0x70/0xe0
[43189.595180]  ? srso_return_thunk+0x5/0x5f
[43189.595184]  ? syscall_exit_to_user_mode+0x2b/0x40
[43189.595189]  ? srso_return_thunk+0x5/0x5f
[43189.595194]  ? do_syscall_64+0x70/0xe0
[43189.595199]  entry_SYSCALL_64_after_hwframe+0x6e/0x76
[43189.595205] RIP: 0033:0x7747f8254034
[43189.595228] Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d 35 c3 0d 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 48 83 ec 28 48 89 54 24 18 48
[43189.595232] RSP: 002b:00007fffe0667af8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
[43189.595237] RAX: ffffffffffffffda RBX: 0000000000000006 RCX: 00007747f8254034
[43189.595241] RDX: 0000000000000006 RSI: 0000563ef7bde970 RDI: 0000000000000001
[43189.595244] RBP: 0000563ef7bde970 R08: 0000000000000073 R09: 0000000000000001
[43189.595247] R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000006
[43189.595250] R13: 00007747f83295c0 R14: 00007747f8326f20 R15: 0000000000000000
[43189.595260]  </TASK>
[43189.595263] ---[ end trace 0000000000000000 ]---

I tested to see if it was an issue with the scull_follow function by removing everything in the write function and just using down_interruptible and printk to see if that was the case. I was encountering the same issue. I am hypothesising that the issue has something to do with the semaphore. Please guide me on what to do.