Re: [PATCH net-next 01/11] atm: horizon: shut up clang null pointer arithmetic warning

From: Arnd Bergmann
Date: Tue Oct 27 2020 - 09:24:08 EST


On Tue, Oct 27, 2020 at 5:02 AM Xie He <xie.he.0141@xxxxxxxxx> wrote:
>
> On Mon, Oct 26, 2020 at 8:56 PM Xie He <xie.he.0141@xxxxxxxxx> wrote:
> >
> > > - for (mem = (HDW *) memmap; mem < (HDW *) (memmap + 1); ++mem)
> > > + for (mem = (HDW *) memmap; mem < (HDW *) ((uintptr_t)memmap + 1); ++mem)
> >
> > Note that these two lines are semantically different. In the first line,
> > "+ 1" moves the pointer by (sizeof memmap) bytes. However in the second
> > line, "+ 1" moves the pointer by only 1 byte.
>
> Correction: in the first line "+ 1" moves the pointer by (sizeof *memmap) bytes.

Ah, of course. I had looked up the types but mixed up the memmap
and HDW definitions, but then got confused trying to understand the
logic in wr_mem() that operates on bytes but expands them into
multiples of 4.

I've modified it as below now, will resend along with the other patches
if you think this makes sense.

Arnd

--- a/drivers/atm/horizon.c
+++ b/drivers/atm/horizon.c
@@ -1815,7 +1815,7 @@ static int hrz_init(hrz_dev *dev)

int buff_count;

- HDW * mem;
+ uintptr_t offset;

cell_buf * tx_desc;
cell_buf * rx_desc;
@@ -1841,8 +1841,8 @@ static int hrz_init(hrz_dev *dev)

printk (" clearing memory");

- for (mem = (HDW *) memmap; mem < (HDW *) (memmap + 1); ++mem)
- wr_mem (dev, mem, 0);
+ for (offset = 0; offset < sizeof(struct MEMMAP); offset++)
+ wr_mem (dev, (HDW *)offset, 0);

printk (" tx channels");