ceph: Convert ceph_readdir_cache_control to store a folio
Hello Matthew Wilcox (Oracle),
Commit baff9740bc8f ("ceph: Convert ceph_readdir_cache_control to store a folio") from Feb 17, 2025 (linux-next), leads to the following Smatch static checker warning:
fs/ceph/inode.c:1873 fill_readdir_cache() warn: 'ctl->folio' is an error pointer or valid
fs/ceph/inode.c
1854 static int fill_readdir_cache(struct inode *dir, struct dentry *dn,
1855 struct ceph_readdir_cache_control *ctl,
1856 struct ceph_mds_request *req)
1857 {
1858 struct ceph_client *cl = ceph_inode_to_client(dir);
1859 struct ceph_inode_info *ci = ceph_inode(dir);
1860 unsigned nsize = PAGE_SIZE / sizeof(struct dentry*);
1861 unsigned idx = ctl->index % nsize;
1862 pgoff_t pgoff = ctl->index / nsize;
1863
1864 if (!ctl->folio || pgoff != ctl->folio->index) {
1865 ceph_readdir_cache_release(ctl);
1866 fgf_t fgf = FGP_LOCK;
1867
1868 if (idx == 0)
1869 fgf |= FGP_ACCESSED | FGP_CREAT;
1870
1871 ctl->folio = __filemap_get_folio(&dir->i_data, pgoff,
1872 fgf, mapping_gfp_mask(&dir->i_data));
--> 1873 if (!ctl->folio) {
1874 ctl->index = -1;
1875 return idx == 0 ? -ENOMEM : 0;The __filemap_get_folio() never returns NULL, it returns error pointers.
1876 }
1877 /* reading/filling the cache are serialized by
1878 * i_rwsem, no need to use folio lock */
1879 folio_unlock(ctl->folio);
1880 ctl->dentries = kmap_local_folio(ctl->folio, 0);
1881 if (idx == 0)
1882 memset(ctl->dentries, 0, PAGE_SIZE);
1883 }
1884
1885 if (req->r_dir_release_cnt == atomic64_read(&ci->i_release_count) &&
1886 req->r_dir_ordered_cnt == atomic64_read(&ci->i_ordered_count)) {
1887 doutc(cl, "dn %p idx %d\n", dn, ctl->index);
1888 ctl->dentries[idx] = dn;
1889 ctl->index++;
1890 } else {
1891 doutc(cl, "disable readdir cache\n");
1892 ctl->index = -1;
1893 }
1894 return 0;
1895 }regards,
dan carpenter