From: Dan Carpenter <dan.carpenter@linaro.org>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: linux-fsdevel@vger.kernel.org
Subject: [bug report] ntfs: update attrib operations
Date: Fri, 27 Feb 2026 10:58:54 +0300 [thread overview]
Message-ID: <aaFOvvCNNEsDXXBT@stanley.mountain> (raw)
[ Smatch checking is paused while we raise funding. #SadFace
https://lore.kernel.org/all/aTaiGSbWZ9DJaGo7@stanley.mountain/ -dan ]
Hello Namjae Jeon,
Commit 495e90fa3348 ("ntfs: update attrib operations") from Feb 13,
2026 (linux-next), leads to the following Smatch static checker
warning:
fs/ntfs/attrib.c:5197 ntfs_non_resident_attr_collapse_range()
warn: inconsistent returns '&ni->runlist.lock'.
fs/ntfs/attrib.c
5107 int ntfs_non_resident_attr_collapse_range(struct ntfs_inode *ni, s64 start_vcn, s64 len)
5108 {
5109 struct ntfs_volume *vol = ni->vol;
5110 struct runlist_element *punch_rl, *rl;
5111 struct ntfs_attr_search_ctx *ctx = NULL;
5112 s64 end_vcn;
5113 int dst_cnt;
5114 int ret;
5115 size_t new_rl_cnt;
5116
5117 if (NInoAttr(ni) || ni->type != AT_DATA)
5118 return -EOPNOTSUPP;
5119
5120 end_vcn = ntfs_bytes_to_cluster(vol, ni->allocated_size);
5121 if (start_vcn >= end_vcn)
5122 return -EINVAL;
5123
5124 down_write(&ni->runlist.lock);
5125 ret = ntfs_attr_map_whole_runlist(ni);
5126 if (ret)
5127 return ret;
up_write(&ni->runlist.lock) before returning.
5128
5129 len = min(len, end_vcn - start_vcn);
5130 for (rl = ni->runlist.rl, dst_cnt = 0; rl && rl->length; rl++)
5131 dst_cnt++;
5132 rl = ntfs_rl_find_vcn_nolock(ni->runlist.rl, start_vcn);
5133 if (!rl) {
5134 up_write(&ni->runlist.lock);
5135 return -EIO;
5136 }
5137
5138 rl = ntfs_rl_collapse_range(ni->runlist.rl, dst_cnt + 1,
5139 start_vcn, len, &punch_rl, &new_rl_cnt);
5140 if (IS_ERR(rl)) {
5141 up_write(&ni->runlist.lock);
5142 return PTR_ERR(rl);
5143 }
5144 ni->runlist.rl = rl;
5145 ni->runlist.count = new_rl_cnt;
5146
5147 ni->allocated_size -= ntfs_cluster_to_bytes(vol, len);
5148 if (ni->data_size > ntfs_cluster_to_bytes(vol, start_vcn)) {
5149 if (ni->data_size > ntfs_cluster_to_bytes(vol, (start_vcn + len)))
5150 ni->data_size -= ntfs_cluster_to_bytes(vol, len);
5151 else
5152 ni->data_size = ntfs_cluster_to_bytes(vol, start_vcn);
5153 }
5154 if (ni->initialized_size > ntfs_cluster_to_bytes(vol, start_vcn)) {
5155 if (ni->initialized_size >
5156 ntfs_cluster_to_bytes(vol, start_vcn + len))
5157 ni->initialized_size -= ntfs_cluster_to_bytes(vol, len);
5158 else
5159 ni->initialized_size = ntfs_cluster_to_bytes(vol, start_vcn);
5160 }
5161
5162 if (ni->allocated_size > 0) {
5163 ret = ntfs_attr_update_mapping_pairs(ni, 0);
5164 if (ret) {
5165 up_write(&ni->runlist.lock);
5166 goto out_rl;
5167 }
5168 }
5169 up_write(&ni->runlist.lock);
5170
5171 ctx = ntfs_attr_get_search_ctx(ni, NULL);
5172 if (!ctx) {
5173 ret = -ENOMEM;
5174 goto out_rl;
5175 }
5176
5177 ret = ntfs_attr_lookup(ni->type, ni->name, ni->name_len, CASE_SENSITIVE,
5178 0, NULL, 0, ctx);
5179 if (ret)
5180 goto out_ctx;
5181
5182 ctx->attr->data.non_resident.data_size = cpu_to_le64(ni->data_size);
5183 ctx->attr->data.non_resident.initialized_size = cpu_to_le64(ni->initialized_size);
5184 if (ni->allocated_size == 0)
5185 ntfs_attr_make_resident(ni, ctx);
5186 mark_mft_record_dirty(ctx->ntfs_ino);
5187
5188 ret = ntfs_cluster_free_from_rl(vol, punch_rl);
5189 if (ret)
5190 ntfs_error(vol->sb, "Freeing of clusters failed");
5191 out_ctx:
5192 if (ctx)
5193 ntfs_attr_put_search_ctx(ctx);
5194 out_rl:
5195 kvfree(punch_rl);
5196 mark_mft_record_dirty(ni);
--> 5197 return ret;
5198 }
regards,
dan carpenter
next reply other threads:[~2026-02-27 7:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 7:58 Dan Carpenter [this message]
2026-02-27 9:46 ` [bug report] ntfs: update attrib operations Namjae Jeon
-- strict thread matches above, loose matches on Subject: below --
2026-04-10 6:46 Dan Carpenter
2026-04-10 10:11 Dan Carpenter
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=aaFOvvCNNEsDXXBT@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.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 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.