Skip to contentSkip to conversation

kernel: locking: Updates return value check

PATCH Superseded Atul Kumar Pant 2 participants 2 messages Jul 16, 2023 – Jul 18, 2023 Locking primitives

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel: locking: Updates return value check

Updating the check of return value from debugfs_create_file and debugfs_create_dir to use IS_ERR.

---
 kernel/locking/lock_events.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/locking/lock_events.c +5 -5
index fa2c2f951c6b..e68d82099558 100644
@@ -146,7 +146,7 @@ static int __init init_lockevent_counts(void)
 	struct dentry *d_counts = debugfs_create_dir(LOCK_EVENTS_DIR, NULL);
 	int i;
 
-	if (!d_counts)
+	if (IS_ERR(d_counts))
 		goto out;
 
 	/*
@@ -159,14 +159,14 @@ static int __init init_lockevent_counts(void)
 	for (i = 0; i < lockevent_num; i++) {
 		if (skip_lockevent(lockevent_names[i]))
 			continue;
-		if (!debugfs_create_file(lockevent_names[i], 0400, d_counts,
-					 (void *)(long)i, &fops_lockevent))
+		if (IS_ERR(debugfs_create_file(lockevent_names[i], 0400, d_counts,
+					 (void *)(long)i, &fops_lockevent)))
 			goto fail_undo;
 	}
 
-	if (!debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200,
+	if (IS_ERR(debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200,
 				 d_counts, (void *)(long)LOCKEVENT_reset_cnts,
-				 &fops_lockevent))
+				 &fops_lockevent)))
 		goto fail_undo;
 
 	return 0;
Signature · 6 lines
2.25.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 30 lines · Atul Kumar Pant

Updating the check of return value from debugfs_create_file and debugfs_create_dir to use IS_ERR.

---
  kernel/locking/lock_events.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
kernel/locking/lock_events.c +3 -3
index fa2c2f951c6b..e68d82099558 100644
@@ -146,7 +146,7 @@ static int __init init_lockevent_counts(void)
  	struct dentry *d_counts = debugfs_create_dir(LOCK_EVENTS_DIR, NULL);
  	int i;
 
-	if (!d_counts)
+	if (IS_ERR(d_counts))
  		goto out;
 
  	/*
@@ -159,14 +159,14 @@ static int __init init_lockevent_counts(void)
  	for (i = 0; i < lockevent_num; i++) {
  		if (skip_lockevent(lockevent_names[i]))
  			continue;
-		if (!debugfs_create_file(lockevent_names[i], 0400, d_counts,
-					 (void *)(long)i, &fops_lockevent))
+		if (IS_ERR(debugfs_create_file(lockevent_names[i], 0400, d_counts,
+					 (void *)(long)i, &fops_lockevent)))
  			goto fail_undo;

kernel/locking/lock_events.c static int __init init_lockevent_counts(void) · line 172

Quoted 10 lines
kernel/locking/lock_events.c +2 -2
  	}
 
-	if (!debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200,
+	if (IS_ERR(debugfs_create_file(lockevent_names[LOCKEVENT_reset_cnts], 0200,
  				 d_counts, (void *)(long)LOCKEVENT_reset_cnts,
-				 &fops_lockevent))
+				 &fops_lockevent)))
  		goto fail_undo;
 
  	return 0;

It looks good to me, though the chance of getting an error return is really slim unless there is something really wrong with the system.

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees