Skip to content

Commit

Permalink
gpu: ipu-v3: prg: avoid possible array underflow
Browse files Browse the repository at this point in the history
gcc-8 reports that we access an array with a negative index
in an error case:

drivers/gpu/ipu-v3/ipu-prg.c: In function 'ipu_prg_channel_disable':
drivers/gpu/ipu-v3/ipu-prg.c:252:43: error: array subscript -22 is below array bounds of 'struct ipu_prg_channel[3]' [-Werror=array-bounds]

This moves the range check in front of the first time that
variable gets used.

Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Philipp Zabel <[email protected]>
  • Loading branch information
arndb authored and pH5 committed Mar 15, 2018
1 parent 0c8efd6 commit 746d024
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions drivers/gpu/ipu-v3/ipu-prg.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,14 @@ void ipu_prg_channel_disable(struct ipuv3_channel *ipu_chan)
{
int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
struct ipu_prg_channel *chan = &prg->chan[prg_chan];
struct ipu_prg_channel *chan;
u32 val;

if (!chan->enabled || prg_chan < 0)
if (prg_chan < 0)
return;

chan = &prg->chan[prg_chan];
if (!chan->enabled)
return;

pm_runtime_get_sync(prg->dev);
Expand All @@ -280,13 +284,15 @@ int ipu_prg_channel_configure(struct ipuv3_channel *ipu_chan,
{
int prg_chan = ipu_prg_ipu_to_prg_chan(ipu_chan->num);
struct ipu_prg *prg = ipu_chan->ipu->prg_priv;
struct ipu_prg_channel *chan = &prg->chan[prg_chan];
struct ipu_prg_channel *chan;
u32 val;
int ret;

if (prg_chan < 0)
return prg_chan;

chan = &prg->chan[prg_chan];

if (chan->enabled) {
ipu_pre_update(prg->pres[chan->used_pre], *eba);
return 0;
Expand Down

0 comments on commit 746d024

Please sign in to comment.