All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: oe-kbuild@lists.linux.dev
Cc: lkp@intel.com, Dan Carpenter <error27@gmail.com>
Subject: drivers/android/binder/rust_binderfs.c:134 binderfs_binder_device_create() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?
Date: Thu, 18 Dec 2025 12:51:42 +0800	[thread overview]
Message-ID: <202512181203.IOv6IChH-lkp@intel.com> (raw)

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: linux-kernel@vger.kernel.org
TO: Alice Ryhl <aliceryhl@google.com>
CC: Wedson Almeida Filho <wedsonaf@gmail.com>
CC: Matt Gilbride <mattgilbride@google.com>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   ea1013c1539270e372fc99854bc6e4d94eaeff66
commit: eafedbc7c050c44744fbdf80bdf3315e860b7513 rust_binder: add Rust Binder driver
date:   3 months ago
:::::: branch date: 25 hours ago
:::::: commit date: 3 months ago
config: loongarch-randconfig-r071-20251218 (https://download.01.org/0day-ci/archive/20251218/202512181203.IOv6IChH-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 1335a05ab8bc8339ce24be3a9da89d8c3f4e0571)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202512181203.IOv6IChH-lkp@intel.com/

smatch warnings:
drivers/android/binder/rust_binderfs.c:134 binderfs_binder_device_create() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?
drivers/android/binder/rust_binderfs.c:418 binderfs_binder_ctl_create() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?

vim +/max +134 drivers/android/binder/rust_binderfs.c

eafedbc7c050c4 Alice Ryhl 2025-09-19  130  
eafedbc7c050c4 Alice Ryhl 2025-09-19  131  	/* Reserve new minor number for the new device. */
eafedbc7c050c4 Alice Ryhl 2025-09-19  132  	mutex_lock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  133  	if (++info->device_count <= info->mount_opts.max)
eafedbc7c050c4 Alice Ryhl 2025-09-19 @134  		minor = ida_alloc_max(&binderfs_minors,
eafedbc7c050c4 Alice Ryhl 2025-09-19  135  				      use_reserve ? BINDERFS_MAX_MINOR :
eafedbc7c050c4 Alice Ryhl 2025-09-19  136  						    BINDERFS_MAX_MINOR_CAPPED,
eafedbc7c050c4 Alice Ryhl 2025-09-19  137  				      GFP_KERNEL);
eafedbc7c050c4 Alice Ryhl 2025-09-19  138  	else
eafedbc7c050c4 Alice Ryhl 2025-09-19  139  		minor = -ENOSPC;
eafedbc7c050c4 Alice Ryhl 2025-09-19  140  	if (minor < 0) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  141  		--info->device_count;
eafedbc7c050c4 Alice Ryhl 2025-09-19  142  		mutex_unlock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  143  		return minor;
eafedbc7c050c4 Alice Ryhl 2025-09-19  144  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  145  	mutex_unlock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  146  
eafedbc7c050c4 Alice Ryhl 2025-09-19  147  	ret = -ENOMEM;
eafedbc7c050c4 Alice Ryhl 2025-09-19  148  	device = kzalloc(sizeof(*device), GFP_KERNEL);
eafedbc7c050c4 Alice Ryhl 2025-09-19  149  	if (!device)
eafedbc7c050c4 Alice Ryhl 2025-09-19  150  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  151  
eafedbc7c050c4 Alice Ryhl 2025-09-19  152  	req->name[BINDERFS_MAX_NAME] = '\0'; /* NUL-terminate */
eafedbc7c050c4 Alice Ryhl 2025-09-19  153  
eafedbc7c050c4 Alice Ryhl 2025-09-19  154  	ctx = rust_binder_new_context(req->name);
eafedbc7c050c4 Alice Ryhl 2025-09-19  155  	if (!ctx)
eafedbc7c050c4 Alice Ryhl 2025-09-19  156  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  157  
eafedbc7c050c4 Alice Ryhl 2025-09-19  158  	inode = new_inode(sb);
eafedbc7c050c4 Alice Ryhl 2025-09-19  159  	if (!inode)
eafedbc7c050c4 Alice Ryhl 2025-09-19  160  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  161  
eafedbc7c050c4 Alice Ryhl 2025-09-19  162  	inode->i_ino = minor + INODE_OFFSET;
eafedbc7c050c4 Alice Ryhl 2025-09-19  163  	simple_inode_init_ts(inode);
eafedbc7c050c4 Alice Ryhl 2025-09-19  164  	init_special_inode(inode, S_IFCHR | 0600,
eafedbc7c050c4 Alice Ryhl 2025-09-19  165  			   MKDEV(MAJOR(binderfs_dev), minor));
eafedbc7c050c4 Alice Ryhl 2025-09-19  166  	inode->i_fop = &rust_binder_fops;
eafedbc7c050c4 Alice Ryhl 2025-09-19  167  	inode->i_uid = info->root_uid;
eafedbc7c050c4 Alice Ryhl 2025-09-19  168  	inode->i_gid = info->root_gid;
eafedbc7c050c4 Alice Ryhl 2025-09-19  169  
eafedbc7c050c4 Alice Ryhl 2025-09-19  170  	req->major = MAJOR(binderfs_dev);
eafedbc7c050c4 Alice Ryhl 2025-09-19  171  	req->minor = minor;
eafedbc7c050c4 Alice Ryhl 2025-09-19  172  	device->ctx = ctx;
eafedbc7c050c4 Alice Ryhl 2025-09-19  173  	device->minor = minor;
eafedbc7c050c4 Alice Ryhl 2025-09-19  174  
eafedbc7c050c4 Alice Ryhl 2025-09-19  175  	if (userp && copy_to_user(userp, req, sizeof(*req))) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  176  		ret = -EFAULT;
eafedbc7c050c4 Alice Ryhl 2025-09-19  177  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  178  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  179  
eafedbc7c050c4 Alice Ryhl 2025-09-19  180  	root = sb->s_root;
eafedbc7c050c4 Alice Ryhl 2025-09-19  181  	inode_lock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  182  
eafedbc7c050c4 Alice Ryhl 2025-09-19  183  	/* look it up */
eafedbc7c050c4 Alice Ryhl 2025-09-19  184  	dentry = lookup_noperm(&QSTR(req->name), root);
eafedbc7c050c4 Alice Ryhl 2025-09-19  185  	if (IS_ERR(dentry)) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  186  		inode_unlock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  187  		ret = PTR_ERR(dentry);
eafedbc7c050c4 Alice Ryhl 2025-09-19  188  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  189  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  190  
eafedbc7c050c4 Alice Ryhl 2025-09-19  191  	if (d_really_is_positive(dentry)) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  192  		/* already exists */
eafedbc7c050c4 Alice Ryhl 2025-09-19  193  		dput(dentry);
eafedbc7c050c4 Alice Ryhl 2025-09-19  194  		inode_unlock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  195  		ret = -EEXIST;
eafedbc7c050c4 Alice Ryhl 2025-09-19  196  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  197  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  198  
eafedbc7c050c4 Alice Ryhl 2025-09-19  199  	inode->i_private = device;
eafedbc7c050c4 Alice Ryhl 2025-09-19  200  	d_instantiate(dentry, inode);
eafedbc7c050c4 Alice Ryhl 2025-09-19  201  	fsnotify_create(root->d_inode, dentry);
eafedbc7c050c4 Alice Ryhl 2025-09-19  202  	inode_unlock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  203  
eafedbc7c050c4 Alice Ryhl 2025-09-19  204  	return 0;
eafedbc7c050c4 Alice Ryhl 2025-09-19  205  
eafedbc7c050c4 Alice Ryhl 2025-09-19  206  err:
eafedbc7c050c4 Alice Ryhl 2025-09-19  207  	kfree(device);
eafedbc7c050c4 Alice Ryhl 2025-09-19  208  	rust_binder_remove_context(ctx);
eafedbc7c050c4 Alice Ryhl 2025-09-19  209  	mutex_lock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  210  	--info->device_count;
eafedbc7c050c4 Alice Ryhl 2025-09-19  211  	ida_free(&binderfs_minors, minor);
eafedbc7c050c4 Alice Ryhl 2025-09-19  212  	mutex_unlock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  213  	iput(inode);
eafedbc7c050c4 Alice Ryhl 2025-09-19  214  
eafedbc7c050c4 Alice Ryhl 2025-09-19  215  	return ret;
eafedbc7c050c4 Alice Ryhl 2025-09-19  216  }
eafedbc7c050c4 Alice Ryhl 2025-09-19  217  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@linaro.org>
To: oe-kbuild@lists.linux.dev, Alice Ryhl <aliceryhl@google.com>
Cc: lkp@intel.com, oe-kbuild-all@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Wedson Almeida Filho <wedsonaf@gmail.com>,
	Matt Gilbride <mattgilbride@google.com>
Subject: drivers/android/binder/rust_binderfs.c:134 binderfs_binder_device_create() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?
Date: Thu, 18 Dec 2025 10:17:52 +0300	[thread overview]
Message-ID: <202512181203.IOv6IChH-lkp@intel.com> (raw)
Message-ID: <20251218071752.omIsi0jVF7L3YxQY2GherDcimX3EhZblIJkCW28hLz0@z> (raw)

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   ea1013c1539270e372fc99854bc6e4d94eaeff66
commit: eafedbc7c050c44744fbdf80bdf3315e860b7513 rust_binder: add Rust Binder driver
config: loongarch-randconfig-r071-20251218 (https://download.01.org/0day-ci/archive/20251218/202512181203.IOv6IChH-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 1335a05ab8bc8339ce24be3a9da89d8c3f4e0571)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202512181203.IOv6IChH-lkp@intel.com/

smatch warnings:
drivers/android/binder/rust_binderfs.c:134 binderfs_binder_device_create() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?
drivers/android/binder/rust_binderfs.c:418 binderfs_binder_ctl_create() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing?

vim +/max +134 drivers/android/binder/rust_binderfs.c

eafedbc7c050c4 Alice Ryhl 2025-09-19  130  
eafedbc7c050c4 Alice Ryhl 2025-09-19  131  	/* Reserve new minor number for the new device. */
eafedbc7c050c4 Alice Ryhl 2025-09-19  132  	mutex_lock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  133  	if (++info->device_count <= info->mount_opts.max)
eafedbc7c050c4 Alice Ryhl 2025-09-19 @134  		minor = ida_alloc_max(&binderfs_minors,
eafedbc7c050c4 Alice Ryhl 2025-09-19  135  				      use_reserve ? BINDERFS_MAX_MINOR :
eafedbc7c050c4 Alice Ryhl 2025-09-19  136  						    BINDERFS_MAX_MINOR_CAPPED,

ida_alloc_max() takes the maximum valid id not the count.  These should
be BINDERFS_MAX_MINOR - 1, BINDERFS_MAX_MINOR_CAPPED - 1.

eafedbc7c050c4 Alice Ryhl 2025-09-19  137  				      GFP_KERNEL);
eafedbc7c050c4 Alice Ryhl 2025-09-19  138  	else
eafedbc7c050c4 Alice Ryhl 2025-09-19  139  		minor = -ENOSPC;
eafedbc7c050c4 Alice Ryhl 2025-09-19  140  	if (minor < 0) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  141  		--info->device_count;
eafedbc7c050c4 Alice Ryhl 2025-09-19  142  		mutex_unlock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  143  		return minor;
eafedbc7c050c4 Alice Ryhl 2025-09-19  144  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  145  	mutex_unlock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  146  
eafedbc7c050c4 Alice Ryhl 2025-09-19  147  	ret = -ENOMEM;
eafedbc7c050c4 Alice Ryhl 2025-09-19  148  	device = kzalloc(sizeof(*device), GFP_KERNEL);
eafedbc7c050c4 Alice Ryhl 2025-09-19  149  	if (!device)
eafedbc7c050c4 Alice Ryhl 2025-09-19  150  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  151  
eafedbc7c050c4 Alice Ryhl 2025-09-19  152  	req->name[BINDERFS_MAX_NAME] = '\0'; /* NUL-terminate */
eafedbc7c050c4 Alice Ryhl 2025-09-19  153  
eafedbc7c050c4 Alice Ryhl 2025-09-19  154  	ctx = rust_binder_new_context(req->name);
eafedbc7c050c4 Alice Ryhl 2025-09-19  155  	if (!ctx)
eafedbc7c050c4 Alice Ryhl 2025-09-19  156  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  157  
eafedbc7c050c4 Alice Ryhl 2025-09-19  158  	inode = new_inode(sb);
eafedbc7c050c4 Alice Ryhl 2025-09-19  159  	if (!inode)
eafedbc7c050c4 Alice Ryhl 2025-09-19  160  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  161  
eafedbc7c050c4 Alice Ryhl 2025-09-19  162  	inode->i_ino = minor + INODE_OFFSET;
eafedbc7c050c4 Alice Ryhl 2025-09-19  163  	simple_inode_init_ts(inode);
eafedbc7c050c4 Alice Ryhl 2025-09-19  164  	init_special_inode(inode, S_IFCHR | 0600,
eafedbc7c050c4 Alice Ryhl 2025-09-19  165  			   MKDEV(MAJOR(binderfs_dev), minor));
eafedbc7c050c4 Alice Ryhl 2025-09-19  166  	inode->i_fop = &rust_binder_fops;
eafedbc7c050c4 Alice Ryhl 2025-09-19  167  	inode->i_uid = info->root_uid;
eafedbc7c050c4 Alice Ryhl 2025-09-19  168  	inode->i_gid = info->root_gid;
eafedbc7c050c4 Alice Ryhl 2025-09-19  169  
eafedbc7c050c4 Alice Ryhl 2025-09-19  170  	req->major = MAJOR(binderfs_dev);
eafedbc7c050c4 Alice Ryhl 2025-09-19  171  	req->minor = minor;
eafedbc7c050c4 Alice Ryhl 2025-09-19  172  	device->ctx = ctx;
eafedbc7c050c4 Alice Ryhl 2025-09-19  173  	device->minor = minor;
eafedbc7c050c4 Alice Ryhl 2025-09-19  174  
eafedbc7c050c4 Alice Ryhl 2025-09-19  175  	if (userp && copy_to_user(userp, req, sizeof(*req))) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  176  		ret = -EFAULT;
eafedbc7c050c4 Alice Ryhl 2025-09-19  177  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  178  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  179  
eafedbc7c050c4 Alice Ryhl 2025-09-19  180  	root = sb->s_root;
eafedbc7c050c4 Alice Ryhl 2025-09-19  181  	inode_lock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  182  
eafedbc7c050c4 Alice Ryhl 2025-09-19  183  	/* look it up */
eafedbc7c050c4 Alice Ryhl 2025-09-19  184  	dentry = lookup_noperm(&QSTR(req->name), root);
eafedbc7c050c4 Alice Ryhl 2025-09-19  185  	if (IS_ERR(dentry)) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  186  		inode_unlock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  187  		ret = PTR_ERR(dentry);
eafedbc7c050c4 Alice Ryhl 2025-09-19  188  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  189  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  190  
eafedbc7c050c4 Alice Ryhl 2025-09-19  191  	if (d_really_is_positive(dentry)) {
eafedbc7c050c4 Alice Ryhl 2025-09-19  192  		/* already exists */
eafedbc7c050c4 Alice Ryhl 2025-09-19  193  		dput(dentry);
eafedbc7c050c4 Alice Ryhl 2025-09-19  194  		inode_unlock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  195  		ret = -EEXIST;
eafedbc7c050c4 Alice Ryhl 2025-09-19  196  		goto err;
eafedbc7c050c4 Alice Ryhl 2025-09-19  197  	}
eafedbc7c050c4 Alice Ryhl 2025-09-19  198  
eafedbc7c050c4 Alice Ryhl 2025-09-19  199  	inode->i_private = device;
eafedbc7c050c4 Alice Ryhl 2025-09-19  200  	d_instantiate(dentry, inode);
eafedbc7c050c4 Alice Ryhl 2025-09-19  201  	fsnotify_create(root->d_inode, dentry);
eafedbc7c050c4 Alice Ryhl 2025-09-19  202  	inode_unlock(d_inode(root));
eafedbc7c050c4 Alice Ryhl 2025-09-19  203  
eafedbc7c050c4 Alice Ryhl 2025-09-19  204  	return 0;
eafedbc7c050c4 Alice Ryhl 2025-09-19  205  
eafedbc7c050c4 Alice Ryhl 2025-09-19  206  err:
eafedbc7c050c4 Alice Ryhl 2025-09-19  207  	kfree(device);
eafedbc7c050c4 Alice Ryhl 2025-09-19  208  	rust_binder_remove_context(ctx);
eafedbc7c050c4 Alice Ryhl 2025-09-19  209  	mutex_lock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  210  	--info->device_count;
eafedbc7c050c4 Alice Ryhl 2025-09-19  211  	ida_free(&binderfs_minors, minor);
eafedbc7c050c4 Alice Ryhl 2025-09-19  212  	mutex_unlock(&binderfs_minors_mutex);
eafedbc7c050c4 Alice Ryhl 2025-09-19  213  	iput(inode);
eafedbc7c050c4 Alice Ryhl 2025-09-19  214  
eafedbc7c050c4 Alice Ryhl 2025-09-19  215  	return ret;
eafedbc7c050c4 Alice Ryhl 2025-09-19  216  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


             reply	other threads:[~2025-12-18  4:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18  4:51 kernel test robot [this message]
2025-12-18  7:17 ` drivers/android/binder/rust_binderfs.c:134 binderfs_binder_device_create() error: Calling ida_alloc_max() with a 'max' argument which is a power of 2. -1 missing? Dan Carpenter
2025-12-18  8:10 ` Alice Ryhl
2026-01-27 20:48   ` Carlos Llamas

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=202512181203.IOv6IChH-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=error27@gmail.com \
    --cc=oe-kbuild@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.