[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202509290823.hreUi6Tp-lkp@intel.com>
Date: Mon, 29 Sep 2025 11:46:24 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: oe-kbuild@...ts.linux.dev, Mary Strodl <mstrodl@....rit.edu>,
linux-kernel@...r.kernel.org
Cc: lkp@...el.com, oe-kbuild-all@...ts.linux.dev, linus.walleij@...aro.org,
brgl@...ev.pl, linux-gpio@...r.kernel.org,
Mary Strodl <mstrodl@....rit.edu>
Subject: Re: [PATCH v2 1/3] gpio: mpsse: use rcu to ensure worker is torn down
Hi Mary,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mary-Strodl/gpio-mpsse-use-rcu-to-ensure-worker-is-torn-down/20250923-214710
base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next
patch link: https://lore.kernel.org/r/20250923133304.273529-2-mstrodl%40csh.rit.edu
patch subject: [PATCH v2 1/3] gpio: mpsse: use rcu to ensure worker is torn down
config: i386-randconfig-141-20250929 (https://download.01.org/0day-ci/archive/20250929/202509290823.hreUi6Tp-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
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@...el.com>
| Reported-by: Dan Carpenter <dan.carpenter@...aro.org>
| Closes: https://lore.kernel.org/r/202509290823.hreUi6Tp-lkp@intel.com/
New smatch warnings:
drivers/gpio/gpio-mpsse.c:341 gpio_mpsse_poll() error: dereferencing freed memory 'worker' (line 342)
drivers/gpio/gpio-mpsse.c:604 gpio_mpsse_disconnect() error: dereferencing freed memory 'worker' (line 605)
vim +/worker +341 drivers/gpio/gpio-mpsse.c
a14b0c5e3b0741 Mary Strodl 2025-09-23 304 static void gpio_mpsse_poll(struct work_struct *my_work)
c46a74ff05c0ac Mary Strodl 2024-10-09 305 {
c46a74ff05c0ac Mary Strodl 2024-10-09 306 unsigned long pin_mask, pin_states, flags;
c46a74ff05c0ac Mary Strodl 2024-10-09 307 int irq_enabled, offset, err, value, fire_irq,
c46a74ff05c0ac Mary Strodl 2024-10-09 308 irq, old_value[16], irq_type[16];
a14b0c5e3b0741 Mary Strodl 2025-09-23 309 struct mpsse_worker *worker;
a14b0c5e3b0741 Mary Strodl 2025-09-23 310 struct mpsse_worker *my_worker = container_of(my_work, struct mpsse_worker, work);
a14b0c5e3b0741 Mary Strodl 2025-09-23 311 struct mpsse_priv *priv = my_worker->priv;
a14b0c5e3b0741 Mary Strodl 2025-09-23 312 struct list_head destructors = LIST_HEAD_INIT(destructors);
c46a74ff05c0ac Mary Strodl 2024-10-09 313
c46a74ff05c0ac Mary Strodl 2024-10-09 314 for (offset = 0; offset < priv->gpio.ngpio; ++offset)
c46a74ff05c0ac Mary Strodl 2024-10-09 315 old_value[offset] = -1;
c46a74ff05c0ac Mary Strodl 2024-10-09 316
a14b0c5e3b0741 Mary Strodl 2025-09-23 317 /*
a14b0c5e3b0741 Mary Strodl 2025-09-23 318 * We only want one worker. Workers race to acquire irq_race and tear
a14b0c5e3b0741 Mary Strodl 2025-09-23 319 * down all other workers. This is a cond guard so that we don't deadlock
a14b0c5e3b0741 Mary Strodl 2025-09-23 320 * trying to cancel a worker.
a14b0c5e3b0741 Mary Strodl 2025-09-23 321 */
a14b0c5e3b0741 Mary Strodl 2025-09-23 322 scoped_cond_guard(mutex_try, ;, &priv->irq_race) {
a14b0c5e3b0741 Mary Strodl 2025-09-23 323 scoped_guard(rcu) {
a14b0c5e3b0741 Mary Strodl 2025-09-23 324 list_for_each_entry_rcu(worker, &priv->workers, list) {
a14b0c5e3b0741 Mary Strodl 2025-09-23 325 /* Don't stop ourselves */
a14b0c5e3b0741 Mary Strodl 2025-09-23 326 if (worker == my_worker)
a14b0c5e3b0741 Mary Strodl 2025-09-23 327 continue;
a14b0c5e3b0741 Mary Strodl 2025-09-23 328
a14b0c5e3b0741 Mary Strodl 2025-09-23 329 scoped_guard(raw_spinlock_irqsave, &priv->irq_spin)
a14b0c5e3b0741 Mary Strodl 2025-09-23 330 list_del_rcu(&worker->list);
a14b0c5e3b0741 Mary Strodl 2025-09-23 331
a14b0c5e3b0741 Mary Strodl 2025-09-23 332 /* Give worker a chance to terminate itself */
a14b0c5e3b0741 Mary Strodl 2025-09-23 333 atomic_set(&worker->cancelled, 1);
a14b0c5e3b0741 Mary Strodl 2025-09-23 334 /* Keep track of stuff to cancel */
a14b0c5e3b0741 Mary Strodl 2025-09-23 335 INIT_LIST_HEAD(&worker->destroy);
a14b0c5e3b0741 Mary Strodl 2025-09-23 336 list_add(&worker->destroy, &destructors);
a14b0c5e3b0741 Mary Strodl 2025-09-23 337 }
a14b0c5e3b0741 Mary Strodl 2025-09-23 338 }
a14b0c5e3b0741 Mary Strodl 2025-09-23 339 /* Make sure list consumers are finished before we tear down */
a14b0c5e3b0741 Mary Strodl 2025-09-23 340 synchronize_rcu();
a14b0c5e3b0741 Mary Strodl 2025-09-23 @341 list_for_each_entry(worker, &destructors, destroy)
a14b0c5e3b0741 Mary Strodl 2025-09-23 @342 gpio_mpsse_stop(worker);
This needs to be list_for_each_entry_save() because gpio_mpsse_stop()
frees the worker. Or kfree_rcu() inside an rcu lock or something.
a14b0c5e3b0741 Mary Strodl 2025-09-23 343 }
a14b0c5e3b0741 Mary Strodl 2025-09-23 344
a14b0c5e3b0741 Mary Strodl 2025-09-23 345 while ((irq_enabled = atomic_read(&priv->irq_enabled)) &&
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Powered by blists - more mailing lists