linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: David Howells <dhowells@redhat.com>
Cc: linux-mm@kvack.org
Subject: [bug report] mm: Provide a means of invalidation without using launder_folio
Date: Thu, 13 Jun 2024 16:55:30 +0300	[thread overview]
Message-ID: <8b6bd8e0-04a2-4b51-9b29-74804ba11564@moroto.mountain> (raw)

Hello David Howells,

Commit 74e797d79cf1 ("mm: Provide a means of invalidation without
using launder_folio") from Mar 27, 2024 (linux-next), leads to the
following Smatch static checker warning:

	mm/filemap.c:4229 filemap_invalidate_inode()
	error: we previously assumed 'mapping' could be null (see line 4200)

mm/filemap.c
  4192  int filemap_invalidate_inode(struct inode *inode, bool flush,
  4193                               loff_t start, loff_t end)
  4194  {
  4195          struct address_space *mapping = inode->i_mapping;
  4196          pgoff_t first = start >> PAGE_SHIFT;
  4197          pgoff_t last = end >> PAGE_SHIFT;
  4198          pgoff_t nr = end == LLONG_MAX ? ULONG_MAX : last - first + 1;
  4199  
  4200          if (!mapping || !mapping->nrpages || end < start)
                    ^^^^^^^^
If mapping is NULL

  4201                  goto out;
  4202  
  4203          /* Prevent new folios from being added to the inode. */
  4204          filemap_invalidate_lock(mapping);
  4205  
  4206          if (!mapping->nrpages)
  4207                  goto unlock;
  4208  
  4209          unmap_mapping_pages(mapping, first, nr, false);
  4210  
  4211          /* Write back the data if we're asked to. */
  4212          if (flush) {
  4213                  struct writeback_control wbc = {
  4214                          .sync_mode      = WB_SYNC_ALL,
  4215                          .nr_to_write    = LONG_MAX,
  4216                          .range_start    = start,
  4217                          .range_end      = end,
  4218                  };
  4219  
  4220                  filemap_fdatawrite_wbc(mapping, &wbc);
  4221          }
  4222  
  4223          /* Wait for writeback to complete on all folios and discard. */
  4224          truncate_inode_pages_range(mapping, start, end);
  4225  
  4226  unlock:
  4227          filemap_invalidate_unlock(mapping);
  4228  out:
  4229          return filemap_check_errors(mapping);
                                            ^^^^^^^
Then we're toasted.  The errors from filemap_check_errors() aren't what
I expected.

  4230  }

regards,
dan carpenter


             reply	other threads:[~2024-06-13 13:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-13 13:55 Dan Carpenter [this message]
2024-06-13 14:56 ` Matthew Wilcox
2024-06-13 15:13   ` Dan Carpenter
2024-06-13 15:27     ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8b6bd8e0-04a2-4b51-9b29-74804ba11564@moroto.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=dhowells@redhat.com \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox