linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kari Argillander <kari.argillander@gmail.com>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk,
	linux-kernel@vger.kernel.org, pali@kernel.org, dsterba@suse.cz,
	aaptel@suse.com, willy@infradead.org, rdunlap@infradead.org,
	joe@perches.com, mark@harmstone.com, nborisov@suse.com,
	linux-ntfs-dev@lists.sourceforge.net, anton@tuxera.com,
	dan.carpenter@oracle.com, hch@lst.de, ebiggers@kernel.org,
	andy.lavr@gmail.com
Subject: Re: [PATCH v17 02/10] fs/ntfs3: Add initialization of super block
Date: Tue, 19 Jan 2021 06:03:06 +0200	[thread overview]
Message-ID: <20210119040306.54lm6oyeiarjrb2w@kari-VirtualBox> (raw)
In-Reply-To: <20201231152401.3162425-3-almaz.alexandrovich@paragon-software.com>

On Thu, Dec 31, 2020 at 06:23:53PM +0300, Konstantin Komarov wrote:
> diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c

> +void fnd_clear(struct ntfs_fnd *fnd)
> +{
> +	int i;
> +
> +	for (i = 0; i < fnd->level; i++) {
> +		struct indx_node *n = fnd->nodes[i];
> +
> +		if (!n)
> +			continue;
> +
> +		put_indx_node(n);
> +		fnd->nodes[i] = NULL;
> +	}
> +	fnd->level = 0;
> +	fnd->root_de = NULL;
> +}
> +
> +static int fnd_push(struct ntfs_fnd *fnd, struct indx_node *n,
> +		    struct NTFS_DE *e)
> +{
> +	int i;
> +
> +	i = fnd->level;
> +	if (i < 0 || i >= ARRAY_SIZE(fnd->nodes))
> +		return -EINVAL;
> +	fnd->nodes[i] = n;
> +	fnd->de[i] = e;
> +	fnd->level += 1;
> +	return 0;
> +}
> +
> +static struct indx_node *fnd_pop(struct ntfs_fnd *fnd)
> +{
> +	struct indx_node *n;
> +	int i = fnd->level;
> +
> +	i -= 1;
> +	n = fnd->nodes[i];
> +	fnd->nodes[i] = NULL;
> +	fnd->level = i;
> +
> +	return n;
> +}
> +
> +static bool fnd_is_empty(struct ntfs_fnd *fnd)
> +{
> +	if (!fnd->level)
> +		return !fnd->root_de;
> +
> +	return !fnd->de[fnd->level - 1];
> +}
> +
> +struct ntfs_fnd *fnd_get(struct ntfs_index *indx)
> +{
> +	struct ntfs_fnd *fnd = ntfs_alloc(sizeof(struct ntfs_fnd), 1);
> +
> +	if (!fnd)
> +		return NULL;
> +
> +	return fnd;
> +}

This should be initilized. What about that indx. Is that neccasarry?
Also no need to check NULL because if it is NULL we can just return it. 

> +
> +void fnd_put(struct ntfs_fnd *fnd)
> +{
> +	if (!fnd)
> +		return;
> +	fnd_clear(fnd);
> +	ntfs_free(fnd);
> +}

> +/*
> + * indx_insert_entry
> + *
> + * inserts new entry into index
> + */
> +int indx_insert_entry(struct ntfs_index *indx, struct ntfs_inode *ni,
> +		      const struct NTFS_DE *new_de, const void *ctx,
> +		      struct ntfs_fnd *fnd)
> +{
> +	int err;
> +	int diff;
> +	struct NTFS_DE *e;
> +	struct ntfs_fnd *fnd_a = NULL;
> +	struct INDEX_ROOT *root;
> +
> +	if (!fnd) {
> +		fnd_a = fnd_get(indx);

Here we get uninitilized fnd.

> +		if (!fnd_a) {
> +			err = -ENOMEM;
> +			goto out1;
> +		}
> +		fnd = fnd_a;
> +	}
> +
> +	root = indx_get_root(indx, ni, NULL, NULL);
> +	if (!root) {
> +		err = -EINVAL;
> +		goto out;
> +	}
> +
> +	if (fnd_is_empty(fnd)) {

And example here we try to touch it.

> +		/* Find the spot the tree where we want to insert the new entry. */
> +		err = indx_find(indx, ni, root, new_de + 1,
> +				le16_to_cpu(new_de->key_size), ctx, &diff, &e,
> +				fnd);
> +		if (err)
> +			goto out;
> +
> +		if (!diff) {
> +			err = -EEXIST;
> +			goto out;
> +		}
> +	}
> +
> +	if (!fnd->level) {
> +		/* The root is also a leaf, so we'll insert the new entry into it. */
> +		err = indx_insert_into_root(indx, ni, new_de, fnd->root_de, ctx,
> +					    fnd);
> +		if (err)
> +			goto out;
> +	} else {
> +		/* found a leaf buffer, so we'll insert the new entry into it.*/
> +		err = indx_insert_into_buffer(indx, ni, root, new_de, ctx,
> +					      fnd->level - 1, fnd);
> +		if (err)
> +			goto out;
> +	}
> +
> +out:
> +	fnd_put(fnd_a);
> +out1:
> +	return err;
> +}

  parent reply	other threads:[~2021-01-19  4:06 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-31 15:23 [PATCH v17 00/10] NTFS read-write driver GPL implementation by Paragon Software Konstantin Komarov
2020-12-31 15:23 ` [PATCH v17 01/10] fs/ntfs3: Add headers and misc files Konstantin Komarov
2021-01-03 23:17   ` Kari Argillander
2021-01-19 10:43     ` Dan Carpenter
2021-01-19 20:34       ` Kari Argillander
2020-12-31 15:23 ` [PATCH v17 02/10] fs/ntfs3: Add initialization of super block Konstantin Komarov
2021-01-03 19:50   ` Kari Argillander
2021-01-18  9:35     ` Konstantin Komarov
2021-01-18 14:09       ` Kari Argillander
2021-01-19  4:03   ` Kari Argillander [this message]
2021-01-20  7:20     ` Kari Argillander
2020-12-31 15:23 ` [PATCH v17 03/10] fs/ntfs3: Add bitmap Konstantin Komarov
2020-12-31 15:23 ` [PATCH v17 04/10] fs/ntfs3: Add file operations and implementation Konstantin Komarov
2021-01-03 21:57   ` Kari Argillander
2021-01-03 22:04     ` Matthew Wilcox
2021-01-18 10:00     ` Konstantin Komarov
2021-01-18 14:24       ` Kari Argillander
2021-01-04  2:18   ` Matthew Wilcox
2020-12-31 15:23 ` [PATCH v17 05/10] fs/ntfs3: Add attrib operations Konstantin Komarov
2021-01-04  0:25   ` Kari Argillander
2021-01-18 12:01     ` Konstantin Komarov
2020-12-31 15:23 ` [PATCH v17 06/10] fs/ntfs3: Add compression Konstantin Komarov
2020-12-31 15:23 ` [PATCH v17 07/10] fs/ntfs3: Add NTFS journal Konstantin Komarov
2021-01-03 22:47   ` Kari Argillander
2020-12-31 15:23 ` [PATCH v17 08/10] fs/ntfs3: Add Kconfig, Makefile and doc Konstantin Komarov
2021-01-03 22:07   ` Kari Argillander
2021-01-18 11:43     ` Konstantin Komarov
2021-01-18 13:42       ` Mark Harmstone
2020-12-31 15:24 ` [PATCH v17 09/10] fs/ntfs3: Add NTFS3 in fs/Kconfig and fs/Makefile Konstantin Komarov
2020-12-31 15:24 ` [PATCH v17 10/10] fs/ntfs3: Add MAINTAINERS Konstantin Komarov
2021-01-03 20:01   ` Kari Argillander

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=20210119040306.54lm6oyeiarjrb2w@kari-VirtualBox \
    --to=kari.argillander@gmail.com \
    --cc=aaptel@suse.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=andy.lavr@gmail.com \
    --cc=anton@tuxera.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=ebiggers@kernel.org \
    --cc=hch@lst.de \
    --cc=joe@perches.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ntfs-dev@lists.sourceforge.net \
    --cc=mark@harmstone.com \
    --cc=nborisov@suse.com \
    --cc=pali@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.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;
as well as URLs for NNTP newsgroup(s).