diff mbox series

cifs: fix some build warnings in file.c and smbencrypt.c

Message ID 20220902162155.8310-1-ematsumiya@suse.de
State New
Headers show
Series cifs: fix some build warnings in file.c and smbencrypt.c | expand

Commit Message

Enzo Matsumiya Sept. 2, 2022, 4:21 p.m. UTC
Variable server is already declared in the beginning of
_cifsFileInfo_put() and then again in the close case:

> fs/cifs/file.c: In function ‘_cifsFileInfo_put’:
> fs/cifs/file.c:537:41: error: declaration of ‘server’ shadows a previous local [-Werror=shadow]
>   537 |                 struct TCP_Server_Info *server = tcon->ses->server;
>       |                                         ^~~~~~
> fs/cifs/file.c:487:33: note: shadowed declaration is here
>   487 |         struct TCP_Server_Info *server = tcon->ses->server;

Remove that second declaration since it has the same value.

Also in cifs_setlk(), a struct cifsLockInfo is declared as "lock", same
name as the function parameter:

> fs/cifs/file.c:1815:38: error: declaration of ‘lock’ shadows a parameter [-Werror=shadow]
> 1815 |                 struct cifsLockInfo *lock;
>
> fs/cifs/file.c:1781:48: note: shadowed declaration is here
>  1781 |            bool wait_flag, bool posix_lck, int lock, int unlock,
>       |                                            ~~~~^~~~

Rename the struct to "lock_info", move its declaration to top of
function, and reverse the order of the lock/unlock checks, since in the
unlock case, it's a single line call, and we can goto out earlier. No
functional modifications though.

Also remove the defines in top of smbencrypt.c
(CVAL/SSVALX/SSVAL/true/false) since they're unused.

Signed-off-by: Enzo Matsumiya <ematsumiya@suse.de>
---
 fs/cifs/file.c       | 72 +++++++++++++++++++++-----------------------
 fs/cifs/smbencrypt.c | 12 --------
 2 files changed, 34 insertions(+), 50 deletions(-)
diff mbox series

Patch

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index fa738adc031f..1af16d112967 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -534,7 +534,6 @@  void _cifsFileInfo_put(struct cifsFileInfo *cifs_file,
 		cancel_work_sync(&cifs_file->oplock_break) : false;
 
 	if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
-		struct TCP_Server_Info *server = tcon->ses->server;
 		unsigned int xid;
 
 		xid = get_xid();
@@ -1787,6 +1786,7 @@  cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
 	struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
 	struct TCP_Server_Info *server = tcon->ses->server;
 	struct inode *inode = d_inode(cfile->dentry);
+	struct cifsLockInfo *lock_info;
 
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
 	if (posix_lck) {
@@ -1811,48 +1811,44 @@  cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
 		goto out;
 	}
 #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
-	if (lock) {
-		struct cifsLockInfo *lock;
-
-		lock = cifs_lock_init(flock->fl_start, length, type,
-				      flock->fl_flags);
-		if (!lock)
-			return -ENOMEM;
+	if (unlock) {
+		rc = server->ops->mand_unlock_range(cfile, flock, xid);
+		goto out;
+	}
 
-		rc = cifs_lock_add_if(cfile, lock, wait_flag);
-		if (rc < 0) {
-			kfree(lock);
-			return rc;
-		}
-		if (!rc)
-			goto out;
+	/* lock == true */
+	lock_info = cifs_lock_init(flock->fl_start, length, type, flock->fl_flags);
+	if (!lock_info)
+		return -ENOMEM;
 
-		/*
-		 * Windows 7 server can delay breaking lease from read to None
-		 * if we set a byte-range lock on a file - break it explicitly
-		 * before sending the lock to the server to be sure the next
-		 * read won't conflict with non-overlapted locks due to
-		 * pagereading.
-		 */
-		if (!CIFS_CACHE_WRITE(CIFS_I(inode)) &&
-					CIFS_CACHE_READ(CIFS_I(inode))) {
-			cifs_zap_mapping(inode);
-			cifs_dbg(FYI, "Set no oplock for inode=%p due to mand locks\n",
-				 inode);
-			CIFS_I(inode)->oplock = 0;
-		}
+	rc = cifs_lock_add_if(cfile, lock_info, wait_flag);
+	if (rc < 0) {
+		kfree(lock_info);
+		return rc;
+	}
+	if (!rc)
+		goto out;
 
-		rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
-					    type, 1, 0, wait_flag);
-		if (rc) {
-			kfree(lock);
-			return rc;
-		}
+	/*
+	 * Windows 7 server can delay breaking lease from read to None
+	 * if we set a byte-range lock on a file - break it explicitly
+	 * before sending the lock to the server to be sure the next
+	 * read won't conflict with non-overlapted locks due to
+	 * pagereading.
+	 */
+	if (!CIFS_CACHE_WRITE(CIFS_I(inode)) && CIFS_CACHE_READ(CIFS_I(inode))) {
+		cifs_zap_mapping(inode);
+		cifs_dbg(FYI, "Set no oplock for inode=%p due to mand locks\n", inode);
+		CIFS_I(inode)->oplock = 0;
+	}
 
-		cifs_lock_add(cfile, lock);
-	} else if (unlock)
-		rc = server->ops->mand_unlock_range(cfile, flock, xid);
+	rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, type, 1, 0, wait_flag);
+	if (rc) {
+		kfree(lock_info);
+		return rc;
+	}
 
+	cifs_lock_add(cfile, lock_info);
 out:
 	if ((flock->fl_flags & FL_POSIX) || (flock->fl_flags & FL_FLOCK)) {
 		/*
diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
index 4a0487753869..0214092d2714 100644
--- a/fs/cifs/smbencrypt.c
+++ b/fs/cifs/smbencrypt.c
@@ -26,18 +26,6 @@ 
 #include "cifsproto.h"
 #include "../smbfs_common/md4.h"
 
-#ifndef false
-#define false 0
-#endif
-#ifndef true
-#define true 1
-#endif
-
-/* following came from the other byteorder.h to avoid include conflicts */
-#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
-#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
-#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((__u16)(val)))
-
 /* produce a md4 message digest from data of length n bytes */
 static int
 mdfour(unsigned char *md4_hash, unsigned char *link_str, int link_len)