On Mon, Dec 08, 2025 at 12:20:16AM +0100, Christian Marangi wrote:
On Mon, Dec 08, 2025 at 01:12:03AM +0200, Andy Shevchenko wrote:
On Sun, Dec 07, 2025 at 10:53:48PM +0100, Christian Marangi wrote:
...
static inline resource_size_t resource_size(const struct resource *res) {
- if (!res->start && !res->end)
return 0;I think this breaks or might brake some of the drivers that rely on the proper calculation. If you supply the start and end for the same (if it's not 0), you will get 1 and it's _correct_ result (surprise surprise). One of the thing that may be directly affected (and regress) is the amount of IRQs calculation (which on some platforms may start from 0). However, in practice I think it's none nowadays in the upstream kernel.
One common usage of this is with address size. So if start and end is the same, then it's ok to have size 1?
First of all, resources is not _only_ about the addresses. It may be just... a resource. Whatever it means.
So, second question here is that do we use open or closed interval? I always have an impression that resource model (or in general model with start/end, instead of start/size) uses closed intervals.
Third note, the resources is not only start and end, they also have flags, and this has to be considered when retrieving the content of the resource.
So, in my world, the 1 _is_ the correct result for resource [start .. end], where start = x, and end = x.
return res->end - res->start + 1; }
That said, unfortunately, I think, you want to fix drivers one-by-one and this patch is incorrect as it brings inconsistency to the logic (1 occupied address whatever unit it has may still be valid resource).
Yep but probably never aligned? I don't think there is an arch in the world that is aligned to 1 byte?
I believe you stick to much to the resource == address, no, this is wrong. We have other resources that are not addresses, or we have resource where 0 is _valid_ start point (IO ports, IIRC, is the case, IRQs — of course!).
Also a good start is to add test cases and add/update documentation.
I hoped this was simple enough to have the condition.
I think it needs to be checked first with the actual users.
The more articulate and safe change might be to:
- rename this to __resource_size
- rename every entry of resource_size to __resource_size
- introduce a new resource_size commented and with the check
- Use the new helper where it's actually needed?
Maybe it's simpler and just (almost) nothing should be done? Check what is there, in the resources, before the checks and what flags are being checked before those size checks.
From my search there are various place where the condition is like:
if (resource_size(&res)) ...
And this condition doesn't make any sense since it's always true (I highly suspect these case all fall in what I described)
Not always, I already pointed out that it's not true.
For sure this needs to be discussed and we need to gather more info.