Re: [PATCH v1 1/1] fs/proc/kcore.c: fix coccinelle reported ERROR instances

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 29 Oct 2024 06:46:52 +0100 Mirsad Todorovac <mtodorovac69@xxxxxxxxx> wrote:

> Coccinelle complains about the nested reuse of the pointer `iter' with different
> pointer type:
> 
> ./fs/proc/kcore.c:515:26-30: ERROR: invalid reference to the index variable of the iterator on line 499
> ./fs/proc/kcore.c:534:23-27: ERROR: invalid reference to the index variable of the iterator on line 499
> ./fs/proc/kcore.c:550:40-44: ERROR: invalid reference to the index variable of the iterator on line 499
> ./fs/proc/kcore.c:568:27-31: ERROR: invalid reference to the index variable of the iterator on line 499
> ./fs/proc/kcore.c:581:28-32: ERROR: invalid reference to the index variable of the iterator on line 499
> ./fs/proc/kcore.c:599:27-31: ERROR: invalid reference to the index variable of the iterator on line 499
> ./fs/proc/kcore.c:607:38-42: ERROR: invalid reference to the index variable of the iterator on line 499
> ./fs/proc/kcore.c:614:26-30: ERROR: invalid reference to the index variable of the iterator on line 499
> 
> Replacing `struct kcore_list *iter' with `struct kcore_list *tmp' doesn't change the
> scope and the functionality is the same and coccinelle seems happy.

Well that's dumb of it.  Still, the code is presently a bit weird and
we don't mind working around such third-party issues.

> NOTE: There was an issue with using `struct kcore_list *pos' as the nested iterator.
>       The build did not work!

It worked for me.  What's wrong with that?

> --- a/fs/proc/kcore.c
> +++ b/fs/proc/kcore.c
> @@ -493,13 +493,13 @@ static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
>  		 * the previous entry, search for a matching entry.
>  		 */
>  		if (!m || start < m->addr || start >= m->addr + m->size) {
> -			struct kcore_list *iter;
> +			struct kcore_list *tmp;

`tmp' is a really poor identifier :(

Let's try `pos':

--- a/fs/proc/kcore.c~fs-proc-kcorec-fix-coccinelle-reported-error-instances-fix
+++ a/fs/proc/kcore.c
@@ -493,13 +493,13 @@ static ssize_t read_kcore_iter(struct ki
 		 * the previous entry, search for a matching entry.
 		 */
 		if (!m || start < m->addr || start >= m->addr + m->size) {
-			struct kcore_list *tmp;
+			struct kcore_list *pos;
 
 			m = NULL;
-			list_for_each_entry(tmp, &kclist_head, list) {
-				if (start >= tmp->addr &&
-				    start < tmp->addr + tmp->size) {
-					m = tmp;
+			list_for_each_entry(pos, &kclist_head, list) {
+				if (start >= pos->addr &&
+				    start < pos->addr + pos->size) {
+					m = pos;
 					break;
 				}
 			}
_





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux