All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cifs: avoid possible NULL dereference
@ 2023-09-25  4:52 Su Hui
  2023-09-25 15:07 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Su Hui @ 2023-09-25  4:52 UTC (permalink / raw)
  To: sfrench, pc, lsahlber, sprasad, tom
  Cc: Su Hui, linux-cifs, samba-technical, linux-kernel, kernel-janitors

smatch warn:
fs/smb/client/file.c:4910 cifs_oplock_break() warn:
variable dereferenced before check 'inode' (see line 4881)

If 'inode' is NULL, print some warning and return.

Signed-off-by: Su Hui <suhui@nfschina.com>
---
 fs/smb/client/file.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 2108b3b40ce9..37eed057ded0 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -4878,6 +4878,12 @@ void cifs_oplock_break(struct work_struct *work)
 	struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
 						  oplock_break);
 	struct inode *inode = d_inode(cfile->dentry);
+
+	if (!inode) {
+		cifs_dbg(FYI, "%s : failed to find inode\n", __func__);
+		return;
+	}
+
 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct cifsInodeInfo *cinode = CIFS_I(inode);
 	struct cifs_tcon *tcon;
@@ -4907,7 +4913,7 @@ void cifs_oplock_break(struct work_struct *work)
 		cinode->oplock = 0;
 	}
 
-	if (inode && S_ISREG(inode->i_mode)) {
+	if (S_ISREG(inode->i_mode)) {
 		if (CIFS_CACHE_READ(cinode))
 			break_lease(inode, O_RDONLY);
 		else
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cifs: avoid possible NULL dereference
  2023-09-25  4:52 [PATCH] cifs: avoid possible NULL dereference Su Hui
@ 2023-09-25 15:07 ` Dan Carpenter
  2023-09-26  1:20   ` Su Hui
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2023-09-25 15:07 UTC (permalink / raw)
  To: Su Hui
  Cc: sfrench, pc, lsahlber, sprasad, tom, linux-cifs, samba-technical,
	linux-kernel, kernel-janitors

On Mon, Sep 25, 2023 at 12:52:21PM +0800, Su Hui wrote:
> diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
> index 2108b3b40ce9..37eed057ded0 100644
> --- a/fs/smb/client/file.c
> +++ b/fs/smb/client/file.c
> @@ -4878,6 +4878,12 @@ void cifs_oplock_break(struct work_struct *work)
>  	struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
>  						  oplock_break);
>  	struct inode *inode = d_inode(cfile->dentry);
> +
> +	if (!inode) {
> +		cifs_dbg(FYI, "%s : failed to find inode\n", __func__);
> +		return;
> +	}
> +

Are we allowing this in the middle of the declaration block these days?

>  	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
>  	struct cifsInodeInfo *cinode = CIFS_I(inode);
>  	struct cifs_tcon *tcon;


regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cifs: avoid possible NULL dereference
  2023-09-25 15:07 ` Dan Carpenter
@ 2023-09-26  1:20   ` Su Hui
  0 siblings, 0 replies; 3+ messages in thread
From: Su Hui @ 2023-09-26  1:20 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: sfrench, pc, lsahlber, sprasad, tom, linux-cifs, samba-technical,
	linux-kernel, kernel-janitors

On 2023/9/25 23:07, Dan Carpenter wrote:
> On Mon, Sep 25, 2023 at 12:52:21PM +0800, Su Hui wrote:
>> diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
>> index 2108b3b40ce9..37eed057ded0 100644
>> --- a/fs/smb/client/file.c
>> +++ b/fs/smb/client/file.c
>> @@ -4878,6 +4878,12 @@ void cifs_oplock_break(struct work_struct *work)
>>   	struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
>>   						  oplock_break);
>>   	struct inode *inode = d_inode(cfile->dentry);
>> +
>> +	if (!inode) {
>> +		cifs_dbg(FYI, "%s : failed to find inode\n", __func__);
>> +		return;
>> +	}
>> +
> Are we allowing this in the middle of the declaration block these days?
Really sorry for this, I will modify it right now.
Thanks for your reminder!

Su Hui

>
>>   	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
>>   	struct cifsInodeInfo *cinode = CIFS_I(inode);
>>   	struct cifs_tcon *tcon;
>
> regards,
> dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-26  1:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25  4:52 [PATCH] cifs: avoid possible NULL dereference Su Hui
2023-09-25 15:07 ` Dan Carpenter
2023-09-26  1:20   ` Su Hui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.