On Fri, 2024-04-12 at 12:39 +0200, Oleksii wrote:
> On Mon, 2024-04-08 at 10:23 +0200, Jan Beulich wrote:
> > > +static always_inline void _add_sized(volatile void *p,
> > > +                                     unsigned long x, unsigned
> > > int
> > > size)
> > > +{
> > > +    switch ( size )
> > > +    {
> > > +    case 1: writeb(read_atomic((volatile uint8_t *)p) + x, p);
> > > break;
> > > +    case 2: writew(read_atomic((volatile uint16_t *)p) + x, p);
> > > break;
> > > +    case 4: writel(read_atomic((volatile uint32_t *)p) + x, p);
> > > break;
> > > +#ifndef CONFIG_RISCV_32
> > > +    case 8: writeq(read_atomic((volatile uint64_t *)p) + x, p);
> > > break;
> > > +#endif
> > 
> > Any particular reason for using read_atomic() but write{b,w,l,q}()
> > here?
> It was done because write_atomic() wants to have pointer as a first
> argument, but read_atomic() returns a value.
> 
> As an option it can be used read{b,w,l,q}() instead of read_atomic()
> to
> have the code consistent with write{b,w,l,q}.
> 
> Another option is to left as is and add the comment.
I decided to write it using write_atomic() in the next way:

    case 1:
    {
        uint8_t *t = (volatile uint8_t)p;
        write_atomic(t, read_atomic(t) + x);
        break;
    }
...

~ Oleksii

Reply via email to