linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <w.sang@pengutronix.de>
To: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Rusty Russell <rusty@rustcorp.com.au>,
	Jean Delvare <khali@linux-fr.org>,
	linux-i2c@vger.kernel.org, Roland Dreier <roland@kernel.org>,
	Sean Hefty <sean.hefty@intel.com>,
	Hal Rosenstock <hal.rosenstock@gmail.com>,
	"Marciniszyn, Mike" <mike.marciniszyn@intel.com>,
	Jack Morgenstein <jackm@dev.mellanox.co.il>,
	Or Gerlitz <ogerlitz@mellanox.com>,
	linux-rdma@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH 2/6] idr: remove MAX_IDR_MASK and move left MAX_IDR_* into idr.c
Date: Sun, 10 Feb 2013 12:52:14 +0100	[thread overview]
Message-ID: <20130210115214.GC5472@nekote.pengutronix.de> (raw)
In-Reply-To: <20130208210149.GB26660@mtj.dyndns.org>

On Fri, Feb 08, 2013 at 01:01:49PM -0800, Tejun Heo wrote:
> 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>

For the i2c-part:

Acked-by: Wolfram Sang <wolfram@the-dreams.de>


  parent reply	other threads:[~2013-02-10 11:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-08 21:00 [PATCH 1/6] idr: fix top layer handling Tejun Heo
2013-02-08 21:01 ` [PATCH 2/6] idr: remove MAX_IDR_MASK and move left MAX_IDR_* into idr.c Tejun Heo
2013-02-08 22:09   ` Hefty, Sean
2013-02-09 19:00     ` Tejun Heo
2013-02-10 21:19       ` Hefty, Sean
2013-02-10 11:52   ` Wolfram Sang [this message]
2013-02-08 21:02 ` [PATCH 3/6] idr: remove length restriction from idr_layer->bitmap Tejun Heo
2013-02-08 21:03 ` [PATCH 4/6] idr: make idr_layer larger Tejun Heo
2013-02-08 21:03 ` [PATCH 5/6] idr: add idr_layer->prefix Tejun Heo
2013-02-08 21:03 ` [PATCH 6/6] idr: implement lookup hint Tejun Heo
2013-02-11 23:39 ` [PATCH 1/6] idr: fix top layer handling Andrew Morton
2013-02-12 17:10   ` Tejun Heo
2013-02-12 21:23     ` Andrew Morton

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=20130210115214.GC5472@nekote.pengutronix.de \
    --to=w.sang@pengutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=hal.rosenstock@gmail.com \
    --cc=jackm@dev.mellanox.co.il \
    --cc=khali@linux-fr.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mike.marciniszyn@intel.com \
    --cc=ogerlitz@mellanox.com \
    --cc=roland@kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=sean.hefty@intel.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).