Skip to content

Commit e16269e

Browse files
committed
Fix incorrect open count check in release function
In the original code, the producer stops producing characters when atomic_dec_and_test(&open_cnt) returns zero, but it will return zero when the resulting value of open_cnt is nonzero. Therefore, in the original code, if the open_cnt changes from 2 to 1, it will stop producing characters, but it is supposed to consistently produce characters until the open_cnt becomes zero. Therefore, we modify the code so that it stops producing characters when atomic_dec_and_test(&open_cnt) returns one.
1 parent 9043d41 commit e16269e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

simrupt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static int simrupt_open(struct inode *inode, struct file *filp)
298298
static int simrupt_release(struct inode *inode, struct file *filp)
299299
{
300300
pr_debug("simrupt: %s\n", __func__);
301-
if (atomic_dec_and_test(&open_cnt) == 0) {
301+
if (atomic_dec_and_test(&open_cnt)) {
302302
del_timer_sync(&timer);
303303
flush_workqueue(simrupt_workqueue);
304304
fast_buf_clear();

0 commit comments

Comments
 (0)