2020. augusztus 16., vasárnap 2:51 keltezéssel, Guenter Roeck írta: > On 8/15/20 5:27 PM, Barnabás Pőcze wrote: > >> [...] > >>>> + if (val < (2 ^ 16) - 2) > >>> > >>> Did you intend to write 2 to the power of 16? Because 2^16 is not that. > >>> 2 to the power 16 may be written as '(1 << 16)' or 'BIT(16)' > >>> (you may need to include linux/bits.h for the latter) > >>> > >>> But something like this is my suggestion: > >>> > >>> if (val < 0 || 0xFFFF < val) > >>> return -EINVAL; > >>> > >> > >> I would suggest to use clamp_val; we don't expect users to know device > >> specific limits. Also, FTR, I won't accept any Yoda programming. > >> > >> Guenter > >> [...] > > > > > > If you don't mind me asking, why is that? I, too, don't like Yoda conditions, > > but I've always thought that in this specific case - when checking if a value > > lies within/outside a certain range - it makes the code more easily readable > > if it is written like this: (lo < val && val < hi). > > > > You are suggesting (val < lo || hi < val) here, which is a bit different. > > Anyway, good for you. If you are signing up as code reviewer for a Linux kernel > subsystem, please feel free to accept and promote such code. For me, it is just > confusing. > > Guenter > Thank you for the answer. Barnabás Pőcze