All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: almaz.alexandrovich@paragon-software.com
Cc: ntfs3@lists.linux.dev
Subject: [bug report] fs/ntfs3: Add attrib operations
Date: Tue, 24 Aug 2021 12:42:49 +0300	[thread overview]
Message-ID: <20210824094249.GA22644@kili> (raw)

Hello Konstantin Komarov,

The patch be71b5cba2e6: "fs/ntfs3: Add attrib operations" from Aug
13, 2021, leads to the following
Smatch static checker warning:

	fs/ntfs3/attrib.c:383 attr_set_size_res()
	warn: was expecting a 64 bit value instead of '~7'

fs/ntfs3/attrib.c
    370 static int attr_set_size_res(struct ntfs_inode *ni, struct ATTRIB *attr,
    371 			     struct ATTR_LIST_ENTRY *le, struct mft_inode *mi,
    372 			     u64 new_size, struct runs_tree *run,
    373 			     struct ATTRIB **ins_attr)
    374 {
    375 	struct ntfs_sb_info *sbi = mi->sbi;
    376 	struct MFT_REC *rec = mi->mrec;
    377 	u32 used = le32_to_cpu(rec->used);
    378 	u32 asize = le32_to_cpu(attr->size);
    379 	u32 aoff = PtrOffset(rec, attr);
    380 	u32 rsize = le32_to_cpu(attr->res.data_size);
    381 	u32 tail = used - aoff - asize;
    382 	char *next = Add2Ptr(attr, asize);
--> 383 	s64 dsize = QuadAlign(new_size) - QuadAlign(rsize);
                            ^^^^^^^^^^^^^^^^^^
QuadAlign() is a bad name.

The ntfs3 code has a bunch of bad macros like ntfs_malloc() which will
need to be removed hopefully?  I haven't seen this code before today but
presumably everyone has mentioned this already.

Anyway, new_size is a u64 and QuadAlign() truncates it to u32.  Use the
normal ALIGN() macro.

    384 
    385 	if (dsize < 0) {
    386 		memmove(next + dsize, next, tail);
    387 	} else if (dsize > 0) {
    388 		if (used + dsize > sbi->max_bytes_per_attr)
    389 			return attr_make_nonresident(ni, attr, le, mi, new_size,
    390 						     run, ins_attr, NULL);
    391 
    392 		memmove(next + dsize, next, tail);
    393 		memset(next, 0, dsize);
    394 	}
    395 
    396 	if (new_size > rsize)
    397 		memset(Add2Ptr(resident_data(attr), rsize), 0,
    398 		       new_size - rsize);
    399 
    400 	rec->used = cpu_to_le32(used + dsize);
    401 	attr->size = cpu_to_le32(asize + dsize);
    402 	attr->res.data_size = cpu_to_le32(new_size);
    403 	mi->dirty = true;
    404 	*ins_attr = attr;
    405 
    406 	return 0;
    407 }

regards,
dan carpenter

             reply	other threads:[~2021-08-24  9:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24  9:42 Dan Carpenter [this message]
2021-08-24 10:49 ` [bug report] fs/ntfs3: Add attrib operations Kari Argillander
  -- strict thread matches above, loose matches on Subject: below --
2021-08-24  9:53 Dan Carpenter
2023-07-25 11:45 Dan Carpenter
2026-04-10 10:15 Dan Carpenter
2026-04-15 16:00 ` Konstantin Komarov

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=20210824094249.GA22644@kili \
    --to=dan.carpenter@oracle.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=ntfs3@lists.linux.dev \
    /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.