From: kernel test robot <lkp@intel.com>
To: oe-kbuild@lists.linux.dev
Cc: lkp@intel.com, Julia Lawall <julia.lawall@inria.fr>
Subject: [akpm-mm:mm-new 502/560] drivers/scsi/sg.c:294:1-17: ERROR: sg_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix.
Date: Tue, 15 Sep 2026 16:54:54 +0200 [thread overview]
Message-ID: <202609151628.hydefVEV-lkp@intel.com> (raw)
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: David Hildenbrand <david@kernel.org>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
CC: mm-commits@vger.kernel.org
TO: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-new
head: b08a65b93426d86e3f354d655d6225397b591877
commit: e5b708382008997a5d8652c78d32c4ac43bdc07e [502/560] scsi: sg: convert mmap hook to mmap_prepare and rework
:::::: branch date: 7 hours ago
:::::: commit date: 7 hours ago
config: csky-randconfig-r053-20260915 (https://download.01.org/0day-ci/archive/20260915/202609151628.hydefVEV-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 16.1.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@intel.com>
| Reported-by: Julia Lawall <julia.lawall@inria.fr>
| Closes: https://lore.kernel.org/r/202609151628.hydefVEV-lkp@intel.com/
cocci warnings: (new ones prefixed by >>)
>> drivers/scsi/sg.c:294:1-17: ERROR: sg_fops: .read() can deadlock .write(); change nonseekable_open -> stream_open to fix.
vim +294 drivers/scsi/sg.c
035d12e658fba28 Jörn Engel 2012-04-25 281
cc833acbee9db5c Douglas Gilbert 2014-06-25 282 /* Returns 0 on success, else a negated errno value */
^1da177e4c3f415 Linus Torvalds 2005-04-16 283 static int
^1da177e4c3f415 Linus Torvalds 2005-04-16 284 sg_open(struct inode *inode, struct file *filp)
^1da177e4c3f415 Linus Torvalds 2005-04-16 285 {
^1da177e4c3f415 Linus Torvalds 2005-04-16 286 int dev = iminor(inode);
^1da177e4c3f415 Linus Torvalds 2005-04-16 287 int flags = filp->f_flags;
d6b10348f939794 Mike Christie 2005-11-08 288 struct request_queue *q;
d4e655c49f474de Alexander Wetzel 2024-04-01 289 struct scsi_device *device;
^1da177e4c3f415 Linus Torvalds 2005-04-16 290 Sg_device *sdp;
^1da177e4c3f415 Linus Torvalds 2005-04-16 291 Sg_fd *sfp;
^1da177e4c3f415 Linus Torvalds 2005-04-16 292 int retval;
^1da177e4c3f415 Linus Torvalds 2005-04-16 293
^1da177e4c3f415 Linus Torvalds 2005-04-16 @294 nonseekable_open(inode, filp);
cc833acbee9db5c Douglas Gilbert 2014-06-25 295 if ((flags & O_EXCL) && (O_RDONLY == (flags & O_ACCMODE)))
cc833acbee9db5c Douglas Gilbert 2014-06-25 296 return -EPERM; /* Can't lock it with read only access */
^1da177e4c3f415 Linus Torvalds 2005-04-16 297 sdp = sg_get_dev(dev);
cc833acbee9db5c Douglas Gilbert 2014-06-25 298 if (IS_ERR(sdp))
cc833acbee9db5c Douglas Gilbert 2014-06-25 299 return PTR_ERR(sdp);
^1da177e4c3f415 Linus Torvalds 2005-04-16 300
95e159d6dd808b2 Hannes Reinecke 2014-06-25 301 SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
95e159d6dd808b2 Hannes Reinecke 2014-06-25 302 "sg_open: flags=0x%x\n", flags));
95e159d6dd808b2 Hannes Reinecke 2014-06-25 303
^1da177e4c3f415 Linus Torvalds 2005-04-16 304 /* This driver's module count bumped by fops_get in <linux/fs.h> */
^1da177e4c3f415 Linus Torvalds 2005-04-16 305 /* Prevent the device driver from vanishing while we sleep */
d4e655c49f474de Alexander Wetzel 2024-04-01 306 device = sdp->device;
d4e655c49f474de Alexander Wetzel 2024-04-01 307 retval = scsi_device_get(device);
c6517b7942fad66 Tony Battersby 2009-01-21 308 if (retval)
c6517b7942fad66 Tony Battersby 2009-01-21 309 goto sg_put;
^1da177e4c3f415 Linus Torvalds 2005-04-16 310
cc833acbee9db5c Douglas Gilbert 2014-06-25 311 /* scsi_block_when_processing_errors() may block so bypass
cc833acbee9db5c Douglas Gilbert 2014-06-25 312 * check if O_NONBLOCK. Permits SCSI commands to be issued
cc833acbee9db5c Douglas Gilbert 2014-06-25 313 * during error recovery. Tread carefully. */
^1da177e4c3f415 Linus Torvalds 2005-04-16 314 if (!((flags & O_NONBLOCK) ||
d4e655c49f474de Alexander Wetzel 2024-04-01 315 scsi_block_when_processing_errors(device))) {
^1da177e4c3f415 Linus Torvalds 2005-04-16 316 retval = -ENXIO;
^1da177e4c3f415 Linus Torvalds 2005-04-16 317 /* we are in error recovery for this device */
4045de893f691f7 Bart Van Assche 2024-10-30 318 goto sdp_put;
^1da177e4c3f415 Linus Torvalds 2005-04-16 319 }
^1da177e4c3f415 Linus Torvalds 2005-04-16 320
cc833acbee9db5c Douglas Gilbert 2014-06-25 321 mutex_lock(&sdp->open_rel_lock);
cc833acbee9db5c Douglas Gilbert 2014-06-25 322 if (flags & O_NONBLOCK) {
065b4a2f5952df2 James Bottomley 2013-10-25 323 if (flags & O_EXCL) {
cc833acbee9db5c Douglas Gilbert 2014-06-25 324 if (sdp->open_cnt > 0) {
^1da177e4c3f415 Linus Torvalds 2005-04-16 325 retval = -EBUSY;
cc833acbee9db5c Douglas Gilbert 2014-06-25 326 goto error_mutex_locked;
065b4a2f5952df2 James Bottomley 2013-10-25 327 }
cc833acbee9db5c Douglas Gilbert 2014-06-25 328 } else {
cc833acbee9db5c Douglas Gilbert 2014-06-25 329 if (sdp->exclude) {
^1da177e4c3f415 Linus Torvalds 2005-04-16 330 retval = -EBUSY;
cc833acbee9db5c Douglas Gilbert 2014-06-25 331 goto error_mutex_locked;
^1da177e4c3f415 Linus Torvalds 2005-04-16 332 }
^1da177e4c3f415 Linus Torvalds 2005-04-16 333 }
cc833acbee9db5c Douglas Gilbert 2014-06-25 334 } else {
cc833acbee9db5c Douglas Gilbert 2014-06-25 335 retval = open_wait(sdp, flags);
cc833acbee9db5c Douglas Gilbert 2014-06-25 336 if (retval) /* -ERESTARTSYS or -ENODEV */
cc833acbee9db5c Douglas Gilbert 2014-06-25 337 goto error_mutex_locked;
bafc8ad82d482f9 James Bottomley 2013-10-25 338 }
cc833acbee9db5c Douglas Gilbert 2014-06-25 339
cc833acbee9db5c Douglas Gilbert 2014-06-25 340 /* N.B. at this point we are holding the open_rel_lock */
cc833acbee9db5c Douglas Gilbert 2014-06-25 341 if (flags & O_EXCL)
cc833acbee9db5c Douglas Gilbert 2014-06-25 342 sdp->exclude = true;
cc833acbee9db5c Douglas Gilbert 2014-06-25 343
cc833acbee9db5c Douglas Gilbert 2014-06-25 344 if (sdp->open_cnt < 1) { /* no existing opens */
^1da177e4c3f415 Linus Torvalds 2005-04-16 345 sdp->sgdebug = 0;
d4e655c49f474de Alexander Wetzel 2024-04-01 346 q = device->request_queue;
8a78362c4eefc1d Martin K. Petersen 2010-02-26 347 sdp->sg_tablesize = queue_max_segments(q);
^1da177e4c3f415 Linus Torvalds 2005-04-16 348 }
95e159d6dd808b2 Hannes Reinecke 2014-06-25 349 sfp = sg_add_sfp(sdp);
cc833acbee9db5c Douglas Gilbert 2014-06-25 350 if (IS_ERR(sfp)) {
cc833acbee9db5c Douglas Gilbert 2014-06-25 351 retval = PTR_ERR(sfp);
cc833acbee9db5c Douglas Gilbert 2014-06-25 352 goto out_undo;
cc833acbee9db5c Douglas Gilbert 2014-06-25 353 }
cc833acbee9db5c Douglas Gilbert 2014-06-25 354
^1da177e4c3f415 Linus Torvalds 2005-04-16 355 filp->private_data = sfp;
cc833acbee9db5c Douglas Gilbert 2014-06-25 356 sdp->open_cnt++;
cc833acbee9db5c Douglas Gilbert 2014-06-25 357 mutex_unlock(&sdp->open_rel_lock);
cc833acbee9db5c Douglas Gilbert 2014-06-25 358
cc833acbee9db5c Douglas Gilbert 2014-06-25 359 retval = 0;
cc833acbee9db5c Douglas Gilbert 2014-06-25 360 sg_put:
cc833acbee9db5c Douglas Gilbert 2014-06-25 361 kref_put(&sdp->d_ref, sg_device_destroy);
cc833acbee9db5c Douglas Gilbert 2014-06-25 362 return retval;
cc833acbee9db5c Douglas Gilbert 2014-06-25 363
cc833acbee9db5c Douglas Gilbert 2014-06-25 364 out_undo:
c6517b7942fad66 Tony Battersby 2009-01-21 365 if (flags & O_EXCL) {
cc833acbee9db5c Douglas Gilbert 2014-06-25 366 sdp->exclude = false; /* undo if error */
cc833acbee9db5c Douglas Gilbert 2014-06-25 367 wake_up_interruptible(&sdp->open_wait);
065b4a2f5952df2 James Bottomley 2013-10-25 368 }
cc833acbee9db5c Douglas Gilbert 2014-06-25 369 error_mutex_locked:
cc833acbee9db5c Douglas Gilbert 2014-06-25 370 mutex_unlock(&sdp->open_rel_lock);
bc4f24014de58f0 Alan Stern 2010-06-17 371 sdp_put:
d4e655c49f474de Alexander Wetzel 2024-04-01 372 kref_put(&sdp->d_ref, sg_device_destroy);
d4e655c49f474de Alexander Wetzel 2024-04-01 373 scsi_device_put(device);
d4e655c49f474de Alexander Wetzel 2024-04-01 374 return retval;
^1da177e4c3f415 Linus Torvalds 2005-04-16 375 }
^1da177e4c3f415 Linus Torvalds 2005-04-16 376
:::::: The code at line 294 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2
:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
reply other threads:[~2026-09-15 14:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=202609151628.hydefVEV-lkp@intel.com \
--to=lkp@intel.com \
--cc=julia.lawall@inria.fr \
--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.