Skip to content

Commit

Permalink
ntb: off by one sanity checks
Browse files Browse the repository at this point in the history
These tests are off by one.  If "mw" is equal to NTB_NUM_MW then we
would go beyond the end of the ndev->mw[] array.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jon Mason <jon.mason@intel.com>
  • Loading branch information
Dan Carpenter authored and Jon Mason committed May 15, 2013
1 parent 186f27f commit ad3e275
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/ntb/ntb_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ int ntb_read_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 *val)
*/
void __iomem *ntb_get_mw_vbase(struct ntb_device *ndev, unsigned int mw)
{
if (mw > NTB_NUM_MW)
if (mw >= NTB_NUM_MW)
return NULL;

return ndev->mw[mw].vbase;
Expand All @@ -362,7 +362,7 @@ void __iomem *ntb_get_mw_vbase(struct ntb_device *ndev, unsigned int mw)
*/
resource_size_t ntb_get_mw_size(struct ntb_device *ndev, unsigned int mw)
{
if (mw > NTB_NUM_MW)
if (mw >= NTB_NUM_MW)
return 0;

return ndev->mw[mw].bar_sz;
Expand All @@ -380,7 +380,7 @@ resource_size_t ntb_get_mw_size(struct ntb_device *ndev, unsigned int mw)
*/
void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr)
{
if (mw > NTB_NUM_MW)
if (mw >= NTB_NUM_MW)
return;

dev_dbg(&ndev->pdev->dev, "Writing addr %Lx to BAR %d\n", addr,
Expand Down

0 comments on commit ad3e275

Please sign in to comment.