remarkable-linux/drivers
Tejun Heo e8c8d1bc06 idr: remove MAX_IDR_MASK and move left MAX_IDR_* into idr.c
MAX_IDR_MASK is another weirdness in the idr interface.  As idr covers
whole positive integer range, it's defined as 0x7fffffff or INT_MAX.

Its usage in idr_find(), idr_replace() and idr_remove() is bizarre.
They basically mask off the sign bit and operate on the rest, so if
the caller, by accident, passes in a negative number, the sign bit
will be masked off and the remaining part will be used as if that was
the input, which is worse than crashing.

The constant is visible in idr.h and there are several users in the
kernel.

* drivers/i2c/i2c-core.c:i2c_add_numbered_adapter()

  Basically used to test if adap->nr is a negative number which isn't
  -1 and returns -EINVAL if so.  idr_alloc() already has negative
  @start checking (w/ WARN_ON_ONCE), so this can go away.

* drivers/infiniband/core/cm.c:cm_alloc_id()
  drivers/infiniband/hw/mlx4/cm.c:id_map_alloc()

  Used to wrap cyclic @start.  Can be replaced with max(next, 0).
  Note that this type of cyclic allocation using idr is buggy.  These
  are prone to spurious -ENOSPC failure after the first wraparound.

* fs/super.c:get_anon_bdev()

  The ID allocated from ida is masked off before being tested whether
  it's inside valid range.  ida allocated ID can never be a negative
  number and the masking is unnecessary.

Update idr_*() functions to fail with -EINVAL when negative @id is
specified and update other MAX_IDR_MASK users as described above.

This leaves MAX_IDR_MASK without any user, remove it and relocate
other MAX_IDR_* constants to lib/idr.c.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Roland Dreier <roland@kernel.org>
Cc: Sean Hefty <sean.hefty@intel.com>
Cc: Hal Rosenstock <hal.rosenstock@gmail.com>
Cc: "Marciniszyn, Mike" <mike.marciniszyn@intel.com>
Cc: Jack Morgenstein <jackm@dev.mellanox.co.il>
Cc: Or Gerlitz <ogerlitz@mellanox.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: Wolfram Sang <wolfram@the-dreams.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-27 19:10:20 -08:00
..
accessibility
acpi ACPI and power management fixes for 3.9-rc1 2013-02-25 21:25:17 -08:00
amba
ata 1) apply, and then revert, the sysfs export of ATA host controller number. 2013-02-24 17:32:15 -08:00
atm atm/nicstar: convert to idr_alloc() 2013-02-27 19:10:15 -08:00
auxdisplay
base Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
bcma
block drbd: convert to idr_alloc() 2013-02-27 19:10:15 -08:00
bluetooth
bus
cdrom
char Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
clk
clocksource Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2013-02-26 19:43:20 -08:00
connector
cpufreq ACPI and power management fixes for 3.9-rc1 2013-02-25 21:25:17 -08:00
cpuidle
crypto Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2013-02-25 15:56:15 -08:00
dca dca: convert to idr_alloc() 2013-02-27 19:10:15 -08:00
devfreq
dio
dma dmaengine: convert to idr_alloc() 2013-02-27 19:10:15 -08:00
edac
eisa
extcon
firewire firewire: convert to idr_alloc() 2013-02-27 19:10:15 -08:00
firmware memory-hotplug: remove /sys/firmware/memmap/X sysfs 2013-02-23 17:50:12 -08:00
gpio gpio: convert to idr_alloc() 2013-02-27 19:10:15 -08:00
gpu drm/vmwgfx: convert to idr_alloc() 2013-02-27 19:10:16 -08:00
hid Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
hsi
hv
hwmon
hwspinlock
i2c idr: remove MAX_IDR_MASK and move left MAX_IDR_* into idr.c 2013-02-27 19:10:20 -08:00
ide Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
idle Merge branch 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2013-02-22 19:25:09 -08:00
iio
infiniband idr: remove MAX_IDR_MASK and move left MAX_IDR_* into idr.c 2013-02-27 19:10:20 -08:00
input This is the MFD pull request for the 3.9 merge window. 2013-02-24 20:00:58 -08:00
iommu Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
ipack
irqchip
isdn Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
leds Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney/linux-leds 2013-02-26 09:29:02 -08:00
lguest All trivial, thanks to the stuff which didn't quite make it time. 2013-02-26 14:49:12 -08:00
macintosh Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc 2013-02-23 17:09:55 -08:00
mailbox
md dm: convert to idr_alloc() 2013-02-27 19:10:17 -08:00
media Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
memory
memstick memstick: convert to idr_alloc() 2013-02-27 19:10:17 -08:00
message
mfd mfd: convert to idr_alloc() 2013-02-27 19:10:17 -08:00
misc misc/tifm_core: convert to idr_alloc() 2013-02-27 19:10:17 -08:00
mmc mmc: convert to idr_alloc() 2013-02-27 19:10:17 -08:00
mtd mtd: convert to idr_alloc() 2013-02-27 19:10:18 -08:00
net ppp: convert to idr_alloc() 2013-02-27 19:10:18 -08:00
nfc
ntb
nubus
of
oprofile oprofilefs: add missing ->i_mutex locking in object creation 2013-02-22 23:31:38 -05:00
parisc Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
parport
pci Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
pcmcia
pinctrl
platform Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
pnp Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
power power: convert to idr_alloc() 2013-02-27 19:10:18 -08:00
pps pps: convert to idr_alloc() 2013-02-27 19:10:18 -08:00
ps3
ptp
pwm pwm: Changes for v3.9-rc1 2013-02-26 09:34:29 -08:00
rapidio
regulator
remoteproc remoteproc: convert to idr_alloc() 2013-02-27 19:10:18 -08:00
rpmsg rpmsg: convert to idr_alloc() 2013-02-27 19:10:18 -08:00
rtc This is the MFD pull request for the 3.9 merge window. 2013-02-24 20:00:58 -08:00
s390 Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
sbus Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
scsi scsi/lpfc: convert to idr_alloc() 2013-02-27 19:10:19 -08:00
sfi
sh
sn
spi
ssb
staging Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
target target/iscsi: convert to idr_alloc() 2013-02-27 19:10:18 -08:00
tc
thermal thermal: convert to idr_alloc() 2013-02-27 19:10:19 -08:00
tty sysrq: don't depend on weak undefined arrays to have an address that compares as NULL 2013-02-27 09:59:50 -08:00
uio uio: convert to idr_alloc() 2013-02-27 19:10:19 -08:00
usb Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
uwb
vfio vfio: convert to idr_alloc() 2013-02-27 19:10:19 -08:00
vhost Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2013-02-26 11:42:23 -08:00
video backlight: add new lp8788 backlight driver 2013-02-27 19:10:09 -08:00
virt
virtio All trivial, thanks to the stuff which didn't quite make it time. 2013-02-26 14:49:12 -08:00
vlynq
vme
w1
watchdog Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
xen Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
zorro new helper: file_inode(file) 2013-02-22 23:31:31 -05:00
Kconfig
Makefile Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc 2013-02-23 17:09:55 -08:00