* [Outreachy kernel] [PATCH] gpu: drm: Use list_first_entry instead of list_entry @ 2018-03-18 21:51 Arushi Singhal 2018-03-19 9:40 ` [Outreachy kernel] " Christian König 0 siblings, 1 reply; 5+ messages in thread From: Arushi Singhal @ 2018-03-18 21:51 UTC (permalink / raw) To: alexander.deucher Cc: Christian König, David (ChunMing) Zhou, David Airlie, Tomi Valkeinen, amd-gfx, dri-devel, linux-kernel, outreachy-kernel This patch replaces list_entry with list_first_entry as it makes the code more clear. Done using coccinelle: @@ expression e; @@ ( - list_entry(e->next, + list_first_entry(e, ...) | - list_entry(e->prev, + list_last_entry(e, ...) ) Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c | 4 ++-- drivers/gpu/drm/omapdrm/dss/display.c | 4 ++-- drivers/gpu/drm/radeon/radeon_sa.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c index 3144400..646f593 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c @@ -158,7 +158,7 @@ static void amdgpu_sa_bo_try_free(struct amdgpu_sa_manager *sa_manager) if (sa_manager->hole->next == &sa_manager->olist) return; - sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist); + sa_bo = list_first_entry(sa_manager->hole, struct amdgpu_sa_bo, olist); list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { if (sa_bo->fence == NULL || !dma_fence_is_signaled(sa_bo->fence)) { @@ -183,7 +183,7 @@ static inline unsigned amdgpu_sa_bo_hole_eoffset(struct amdgpu_sa_manager *sa_ma struct list_head *hole = sa_manager->hole; if (hole->next != &sa_manager->olist) { - return list_entry(hole->next, struct amdgpu_sa_bo, olist)->soffset; + return list_first_entry(hole, struct amdgpu_sa_bo, olist)->soffset; } return sa_manager->size; } diff --git a/drivers/gpu/drm/omapdrm/dss/display.c b/drivers/gpu/drm/omapdrm/dss/display.c index 0c9480b..fb9ecae 100644 --- a/drivers/gpu/drm/omapdrm/dss/display.c +++ b/drivers/gpu/drm/omapdrm/dss/display.c @@ -158,8 +158,8 @@ struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from) goto out; } - dssdev = list_entry(l->next, struct omap_dss_device, - panel_list); + dssdev = list_first_entry(l, struct omap_dss_device, + panel_list); omap_dss_get_device(dssdev); goto out; } diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c index 197b157..66c0482 100644 --- a/drivers/gpu/drm/radeon/radeon_sa.c +++ b/drivers/gpu/drm/radeon/radeon_sa.c @@ -158,7 +158,7 @@ static void radeon_sa_bo_try_free(struct radeon_sa_manager *sa_manager) if (sa_manager->hole->next == &sa_manager->olist) return; - sa_bo = list_entry(sa_manager->hole->next, struct radeon_sa_bo, olist); + sa_bo = list_first_entry(sa_manager->hole, struct radeon_sa_bo, olist); list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { if (sa_bo->fence == NULL || !radeon_fence_signaled(sa_bo->fence)) { return; @@ -182,7 +182,7 @@ static inline unsigned radeon_sa_bo_hole_eoffset(struct radeon_sa_manager *sa_ma struct list_head *hole = sa_manager->hole; if (hole->next != &sa_manager->olist) { - return list_entry(hole->next, struct radeon_sa_bo, olist)->soffset; + return list_first_entry(hole, struct radeon_sa_bo, olist)->soffset; } return sa_manager->size; } -- 2.7.4 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com. To post to this group, send email to outreachy-kernel@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180318215105.GA15431%40seema-Inspiron-15-3567. For more options, visit https://groups.google.com/d/optout. ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Outreachy kernel] Re: [PATCH] gpu: drm: Use list_first_entry instead of list_entry 2018-03-18 21:51 [Outreachy kernel] [PATCH] gpu: drm: Use list_first_entry instead of list_entry Arushi Singhal @ 2018-03-19 9:40 ` Christian König 2018-03-19 11:06 ` Julia Lawall 0 siblings, 1 reply; 5+ messages in thread From: Christian König @ 2018-03-19 9:40 UTC (permalink / raw) To: Arushi Singhal, alexander.deucher Cc: David Airlie, linux-kernel, dri-devel, outreachy-kernel, Tomi Valkeinen, amd-gfx, Christian König Mhm, actually that patch isn't correct. What we grab get here is the next entry, not the first one. We don't have an alias list_next_entry for list_first_entry? Regards, Christian. Am 18.03.2018 um 22:51 schrieb Arushi Singhal: > This patch replaces list_entry with list_first_entry as it makes the > code more clear. > Done using coccinelle: > > @@ > expression e; > @@ > ( > - list_entry(e->next, > + list_first_entry(e, > ...) > | > - list_entry(e->prev, > + list_last_entry(e, > ...) > ) > > Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c | 4 ++-- > drivers/gpu/drm/omapdrm/dss/display.c | 4 ++-- > drivers/gpu/drm/radeon/radeon_sa.c | 4 ++-- > 3 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c > index 3144400..646f593 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c > @@ -158,7 +158,7 @@ static void amdgpu_sa_bo_try_free(struct amdgpu_sa_manager *sa_manager) > if (sa_manager->hole->next == &sa_manager->olist) > return; > > - sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist); > + sa_bo = list_first_entry(sa_manager->hole, struct amdgpu_sa_bo, olist); > list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { > if (sa_bo->fence == NULL || > !dma_fence_is_signaled(sa_bo->fence)) { > @@ -183,7 +183,7 @@ static inline unsigned amdgpu_sa_bo_hole_eoffset(struct amdgpu_sa_manager *sa_ma > struct list_head *hole = sa_manager->hole; > > if (hole->next != &sa_manager->olist) { > - return list_entry(hole->next, struct amdgpu_sa_bo, olist)->soffset; > + return list_first_entry(hole, struct amdgpu_sa_bo, olist)->soffset; > } > return sa_manager->size; > } > diff --git a/drivers/gpu/drm/omapdrm/dss/display.c b/drivers/gpu/drm/omapdrm/dss/display.c > index 0c9480b..fb9ecae 100644 > --- a/drivers/gpu/drm/omapdrm/dss/display.c > +++ b/drivers/gpu/drm/omapdrm/dss/display.c > @@ -158,8 +158,8 @@ struct omap_dss_device *omap_dss_get_next_device(struct omap_dss_device *from) > goto out; > } > > - dssdev = list_entry(l->next, struct omap_dss_device, > - panel_list); > + dssdev = list_first_entry(l, struct omap_dss_device, > + panel_list); > omap_dss_get_device(dssdev); > goto out; > } > diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c > index 197b157..66c0482 100644 > --- a/drivers/gpu/drm/radeon/radeon_sa.c > +++ b/drivers/gpu/drm/radeon/radeon_sa.c > @@ -158,7 +158,7 @@ static void radeon_sa_bo_try_free(struct radeon_sa_manager *sa_manager) > if (sa_manager->hole->next == &sa_manager->olist) > return; > > - sa_bo = list_entry(sa_manager->hole->next, struct radeon_sa_bo, olist); > + sa_bo = list_first_entry(sa_manager->hole, struct radeon_sa_bo, olist); > list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { > if (sa_bo->fence == NULL || !radeon_fence_signaled(sa_bo->fence)) { > return; > @@ -182,7 +182,7 @@ static inline unsigned radeon_sa_bo_hole_eoffset(struct radeon_sa_manager *sa_ma > struct list_head *hole = sa_manager->hole; > > if (hole->next != &sa_manager->olist) { > - return list_entry(hole->next, struct radeon_sa_bo, olist)->soffset; > + return list_first_entry(hole, struct radeon_sa_bo, olist)->soffset; > } > return sa_manager->size; > } -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com. To post to this group, send email to outreachy-kernel@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/8b1e22f8-7a05-b66b-8825-7d4d97e46dac%40amd.com. For more options, visit https://groups.google.com/d/optout. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Outreachy kernel] Re: [PATCH] gpu: drm: Use list_first_entry instead of list_entry 2018-03-19 9:40 ` [Outreachy kernel] " Christian König @ 2018-03-19 11:06 ` Julia Lawall 2018-03-19 13:15 ` Christian König 0 siblings, 1 reply; 5+ messages in thread From: Julia Lawall @ 2018-03-19 11:06 UTC (permalink / raw) To: Christian König Cc: Arushi Singhal, alexander.deucher, David Airlie, linux-kernel, dri-devel, outreachy-kernel, Tomi Valkeinen, amd-gfx [-- Attachment #1: Type: text/plain, Size: 5258 bytes --] On Mon, 19 Mar 2018, Christian König wrote: > Mhm, actually that patch isn't correct. What we grab get here is the next > entry, not the first one. > > We don't have an alias list_next_entry for list_first_entry? As compared to the semantic patch I proposed earlier today, it would seem that list_first_entry is useful when the types are different? One would have to check the result of course, but a list eleemnt with the same type as the structure that contains the list might be unlikely? julia > > Regards, > Christian. > > Am 18.03.2018 um 22:51 schrieb Arushi Singhal: > > This patch replaces list_entry with list_first_entry as it makes the > > code more clear. > > Done using coccinelle: > > > > @@ > > expression e; > > @@ > > ( > > - list_entry(e->next, > > + list_first_entry(e, > > ...) > > | > > - list_entry(e->prev, > > + list_last_entry(e, > > ...) > > ) > > > > Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> > > --- > > drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c | 4 ++-- > > drivers/gpu/drm/omapdrm/dss/display.c | 4 ++-- > > drivers/gpu/drm/radeon/radeon_sa.c | 4 ++-- > > 3 files changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c > > b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c > > index 3144400..646f593 100644 > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c > > @@ -158,7 +158,7 @@ static void amdgpu_sa_bo_try_free(struct > > amdgpu_sa_manager *sa_manager) > > if (sa_manager->hole->next == &sa_manager->olist) > > return; > > - sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, > > olist); > > + sa_bo = list_first_entry(sa_manager->hole, struct amdgpu_sa_bo, > > olist); > > list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { > > if (sa_bo->fence == NULL || > > !dma_fence_is_signaled(sa_bo->fence)) { > > @@ -183,7 +183,7 @@ static inline unsigned amdgpu_sa_bo_hole_eoffset(struct > > amdgpu_sa_manager *sa_ma > > struct list_head *hole = sa_manager->hole; > > if (hole->next != &sa_manager->olist) { > > - return list_entry(hole->next, struct amdgpu_sa_bo, > > olist)->soffset; > > + return list_first_entry(hole, struct amdgpu_sa_bo, > > olist)->soffset; > > } > > return sa_manager->size; > > } > > diff --git a/drivers/gpu/drm/omapdrm/dss/display.c > > b/drivers/gpu/drm/omapdrm/dss/display.c > > index 0c9480b..fb9ecae 100644 > > --- a/drivers/gpu/drm/omapdrm/dss/display.c > > +++ b/drivers/gpu/drm/omapdrm/dss/display.c > > @@ -158,8 +158,8 @@ struct omap_dss_device *omap_dss_get_next_device(struct > > omap_dss_device *from) > > goto out; > > } > > - dssdev = list_entry(l->next, struct omap_dss_device, > > - panel_list); > > + dssdev = list_first_entry(l, struct omap_dss_device, > > + panel_list); > > omap_dss_get_device(dssdev); > > goto out; > > } > > diff --git a/drivers/gpu/drm/radeon/radeon_sa.c > > b/drivers/gpu/drm/radeon/radeon_sa.c > > index 197b157..66c0482 100644 > > --- a/drivers/gpu/drm/radeon/radeon_sa.c > > +++ b/drivers/gpu/drm/radeon/radeon_sa.c > > @@ -158,7 +158,7 @@ static void radeon_sa_bo_try_free(struct > > radeon_sa_manager *sa_manager) > > if (sa_manager->hole->next == &sa_manager->olist) > > return; > > - sa_bo = list_entry(sa_manager->hole->next, struct radeon_sa_bo, > > olist); > > + sa_bo = list_first_entry(sa_manager->hole, struct radeon_sa_bo, > > olist); > > list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { > > if (sa_bo->fence == NULL || > > !radeon_fence_signaled(sa_bo->fence)) { > > return; > > @@ -182,7 +182,7 @@ static inline unsigned radeon_sa_bo_hole_eoffset(struct > > radeon_sa_manager *sa_ma > > struct list_head *hole = sa_manager->hole; > > if (hole->next != &sa_manager->olist) { > > - return list_entry(hole->next, struct radeon_sa_bo, > > olist)->soffset; > > + return list_first_entry(hole, struct radeon_sa_bo, > > olist)->soffset; > > } > > return sa_manager->size; > > } > > -- > You received this message because you are subscribed to the Google Groups > "outreachy-kernel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to outreachy-kernel+unsubscribe@googlegroups.com. > To post to this group, send email to outreachy-kernel@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/outreachy-kernel/8b1e22f8-7a05-b66b-8825-7d4d97e46dac%40amd.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com. To post to this group, send email to outreachy-kernel@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.20.1803191204550.3392%40hadrien. For more options, visit https://groups.google.com/d/optout. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Outreachy kernel] Re: [PATCH] gpu: drm: Use list_first_entry instead of list_entry 2018-03-19 11:06 ` Julia Lawall @ 2018-03-19 13:15 ` Christian König 2018-03-19 13:17 ` Fwd: " Christian König 0 siblings, 1 reply; 5+ messages in thread From: Christian König @ 2018-03-19 13:15 UTC (permalink / raw) To: Julia Lawall, Christian König Cc: Arushi Singhal, David Airlie, linux-kernel, dri-devel, outreachy-kernel, Tomi Valkeinen, amd-gfx, alexander.deucher [-- Attachment #1: Type: text/plain, Size: 6455 bytes --] Am 19.03.2018 um 12:06 schrieb Julia Lawall: > > On Mon, 19 Mar 2018, Christian König wrote: > >> Mhm, actually that patch isn't correct. What we grab get here is the next >> entry, not the first one. >> >> We don't have an alias list_next_entry for list_first_entry? > As compared to the semantic patch I proposed earlier today, it would seem > that list_first_entry is useful when the types are different? One would > have to check the result of course, but a list eleemnt with the same type > as the structure that contains the list might be unlikely? The list element and the list head have different types in this case: > if (sa_manager->hole->next == &sa_manager->olist) > return; > - sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist); > + sa_bo = list_first_entry(sa_manager->hole, struct amdgpu_sa_bo, olist); sa_manager->olist is the head of the list and sa_manager->hole can point to both the head and any element in the list. The statement "if (sa_manager->hole->next == &sa_manager->olist)" now checks if the next pointer points to the head and if so aborts the function. Then the statement "sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist);" returns the next element after the hole to try to release it. So with the automated change the code is still correct, but NOT easier to understand because we actually don't grab the first element here. Regards, Christian. > > julia > >> Regards, >> Christian. >> >> Am 18.03.2018 um 22:51 schrieb Arushi Singhal: >>> This patch replaces list_entry with list_first_entry as it makes the >>> code more clear. >>> Done using coccinelle: >>> >>> @@ >>> expression e; >>> @@ >>> ( >>> - list_entry(e->next, >>> + list_first_entry(e, >>> ...) >>> | >>> - list_entry(e->prev, >>> + list_last_entry(e, >>> ...) >>> ) >>> >>> Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> >>> --- >>> drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c | 4 ++-- >>> drivers/gpu/drm/omapdrm/dss/display.c | 4 ++-- >>> drivers/gpu/drm/radeon/radeon_sa.c | 4 ++-- >>> 3 files changed, 6 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> index 3144400..646f593 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> @@ -158,7 +158,7 @@ static void amdgpu_sa_bo_try_free(struct >>> amdgpu_sa_manager *sa_manager) >>> if (sa_manager->hole->next == &sa_manager->olist) >>> return; >>> - sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, >>> olist); >>> + sa_bo = list_first_entry(sa_manager->hole, struct amdgpu_sa_bo, >>> olist); >>> list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { >>> if (sa_bo->fence == NULL || >>> !dma_fence_is_signaled(sa_bo->fence)) { >>> @@ -183,7 +183,7 @@ static inline unsigned amdgpu_sa_bo_hole_eoffset(struct >>> amdgpu_sa_manager *sa_ma >>> struct list_head *hole = sa_manager->hole; >>> if (hole->next != &sa_manager->olist) { >>> - return list_entry(hole->next, struct amdgpu_sa_bo, >>> olist)->soffset; >>> + return list_first_entry(hole, struct amdgpu_sa_bo, >>> olist)->soffset; >>> } >>> return sa_manager->size; >>> } >>> diff --git a/drivers/gpu/drm/omapdrm/dss/display.c >>> b/drivers/gpu/drm/omapdrm/dss/display.c >>> index 0c9480b..fb9ecae 100644 >>> --- a/drivers/gpu/drm/omapdrm/dss/display.c >>> +++ b/drivers/gpu/drm/omapdrm/dss/display.c >>> @@ -158,8 +158,8 @@ struct omap_dss_device *omap_dss_get_next_device(struct >>> omap_dss_device *from) >>> goto out; >>> } >>> - dssdev = list_entry(l->next, struct omap_dss_device, >>> - panel_list); >>> + dssdev = list_first_entry(l, struct omap_dss_device, >>> + panel_list); >>> omap_dss_get_device(dssdev); >>> goto out; >>> } >>> diff --git a/drivers/gpu/drm/radeon/radeon_sa.c >>> b/drivers/gpu/drm/radeon/radeon_sa.c >>> index 197b157..66c0482 100644 >>> --- a/drivers/gpu/drm/radeon/radeon_sa.c >>> +++ b/drivers/gpu/drm/radeon/radeon_sa.c >>> @@ -158,7 +158,7 @@ static void radeon_sa_bo_try_free(struct >>> radeon_sa_manager *sa_manager) >>> if (sa_manager->hole->next == &sa_manager->olist) >>> return; >>> - sa_bo = list_entry(sa_manager->hole->next, struct radeon_sa_bo, >>> olist); >>> + sa_bo = list_first_entry(sa_manager->hole, struct radeon_sa_bo, >>> olist); >>> list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { >>> if (sa_bo->fence == NULL || >>> !radeon_fence_signaled(sa_bo->fence)) { >>> return; >>> @@ -182,7 +182,7 @@ static inline unsigned radeon_sa_bo_hole_eoffset(struct >>> radeon_sa_manager *sa_ma >>> struct list_head *hole = sa_manager->hole; >>> if (hole->next != &sa_manager->olist) { >>> - return list_entry(hole->next, struct radeon_sa_bo, >>> olist)->soffset; >>> + return list_first_entry(hole, struct radeon_sa_bo, >>> olist)->soffset; >>> } >>> return sa_manager->size; >>> } >> -- >> You received this message because you are subscribed to the Google Groups >> "outreachy-kernel" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to outreachy-kernel+unsubscribe@googlegroups.com. >> To post to this group, send email to outreachy-kernel@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/outreachy-kernel/8b1e22f8-7a05-b66b-8825-7d4d97e46dac%40amd.com. >> For more options, visit https://groups.google.com/d/optout. > > > > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com. To post to this group, send email to outreachy-kernel@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/dfc1bc65-d6c0-8935-e787-4743d3cdabae%40amd.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #2: Type: text/html, Size: 8362 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Fwd: Re: [Outreachy kernel] Re: [PATCH] gpu: drm: Use list_first_entry instead of list_entry 2018-03-19 13:15 ` Christian König @ 2018-03-19 13:17 ` Christian König 0 siblings, 0 replies; 5+ messages in thread From: Christian König @ 2018-03-19 13:17 UTC (permalink / raw) To: LKML Forwarding to LKML once more because Outlook decided to change it to HTML mail. Christian. Am 19.03.2018 um 12:06 schrieb Julia Lawall: > On Mon, 19 Mar 2018, Christian König wrote: > >> Mhm, actually that patch isn't correct. What we grab get here is the next >> entry, not the first one. >> >> We don't have an alias list_next_entry for list_first_entry? > As compared to the semantic patch I proposed earlier today, it would seem > that list_first_entry is useful when the types are different? One would > have to check the result of course, but a list eleemnt with the same type > as the structure that contains the list might be unlikely? The list element and the list head have different types in this case: > if (sa_manager->hole->next == &sa_manager->olist) > return; > - sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist); > + sa_bo = list_first_entry(sa_manager->hole, struct amdgpu_sa_bo, olist); sa_manager->olist is the head of the list and sa_manager->hole can point to both the head and any element in the list. The statement "if (sa_manager->hole->next == &sa_manager->olist)" now checks if the next pointer points to the head and if so aborts the function. Then the statement "sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist);" returns the next element after the hole to try to release it. So with the automated change the code is still correct, but NOT easier to understand because we actually don't grab the first element here. Regards, Christian. > julia > >> Regards, >> Christian. >> >> Am 18.03.2018 um 22:51 schrieb Arushi Singhal: >>> This patch replaces list_entry with list_first_entry as it makes the >>> code more clear. >>> Done using coccinelle: >>> >>> @@ >>> expression e; >>> @@ >>> ( >>> - list_entry(e->next, >>> + list_first_entry(e, >>> ...) >>> | >>> - list_entry(e->prev, >>> + list_last_entry(e, >>> ...) >>> ) >>> >>> Signed-off-by: Arushi Singhal<arushisinghal19971997@gmail.com> >>> --- >>> drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c | 4 ++-- >>> drivers/gpu/drm/omapdrm/dss/display.c | 4 ++-- >>> drivers/gpu/drm/radeon/radeon_sa.c | 4 ++-- >>> 3 files changed, 6 insertions(+), 6 deletions(-) >>> >>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> index 3144400..646f593 100644 >>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c >>> @@ -158,7 +158,7 @@ static void amdgpu_sa_bo_try_free(struct >>> amdgpu_sa_manager *sa_manager) >>> if (sa_manager->hole->next == &sa_manager->olist) >>> return; >>> - sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, >>> olist); >>> + sa_bo = list_first_entry(sa_manager->hole, struct amdgpu_sa_bo, >>> olist); >>> list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { >>> if (sa_bo->fence == NULL || >>> !dma_fence_is_signaled(sa_bo->fence)) { >>> @@ -183,7 +183,7 @@ static inline unsigned amdgpu_sa_bo_hole_eoffset(struct >>> amdgpu_sa_manager *sa_ma >>> struct list_head *hole = sa_manager->hole; >>> if (hole->next != &sa_manager->olist) { >>> - return list_entry(hole->next, struct amdgpu_sa_bo, >>> olist)->soffset; >>> + return list_first_entry(hole, struct amdgpu_sa_bo, >>> olist)->soffset; >>> } >>> return sa_manager->size; >>> } >>> diff --git a/drivers/gpu/drm/omapdrm/dss/display.c >>> b/drivers/gpu/drm/omapdrm/dss/display.c >>> index 0c9480b..fb9ecae 100644 >>> --- a/drivers/gpu/drm/omapdrm/dss/display.c >>> +++ b/drivers/gpu/drm/omapdrm/dss/display.c >>> @@ -158,8 +158,8 @@ struct omap_dss_device *omap_dss_get_next_device(struct >>> omap_dss_device *from) >>> goto out; >>> } >>> - dssdev = list_entry(l->next, struct omap_dss_device, >>> - panel_list); >>> + dssdev = list_first_entry(l, struct omap_dss_device, >>> + panel_list); >>> omap_dss_get_device(dssdev); >>> goto out; >>> } >>> diff --git a/drivers/gpu/drm/radeon/radeon_sa.c >>> b/drivers/gpu/drm/radeon/radeon_sa.c >>> index 197b157..66c0482 100644 >>> --- a/drivers/gpu/drm/radeon/radeon_sa.c >>> +++ b/drivers/gpu/drm/radeon/radeon_sa.c >>> @@ -158,7 +158,7 @@ static void radeon_sa_bo_try_free(struct >>> radeon_sa_manager *sa_manager) >>> if (sa_manager->hole->next == &sa_manager->olist) >>> return; >>> - sa_bo = list_entry(sa_manager->hole->next, struct radeon_sa_bo, >>> olist); >>> + sa_bo = list_first_entry(sa_manager->hole, struct radeon_sa_bo, >>> olist); >>> list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { >>> if (sa_bo->fence == NULL || >>> !radeon_fence_signaled(sa_bo->fence)) { >>> return; >>> @@ -182,7 +182,7 @@ static inline unsigned radeon_sa_bo_hole_eoffset(struct >>> radeon_sa_manager *sa_ma >>> struct list_head *hole = sa_manager->hole; >>> if (hole->next != &sa_manager->olist) { >>> - return list_entry(hole->next, struct radeon_sa_bo, >>> olist)->soffset; >>> + return list_first_entry(hole, struct radeon_sa_bo, >>> olist)->soffset; >>> } >>> return sa_manager->size; >>> } >> -- >> You received this message because you are subscribed to the Google Groups >> "outreachy-kernel" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email tooutreachy-kernel+unsubscribe@googlegroups.com. >> To post to this group, send email tooutreachy-kernel@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/outreachy-kernel/8b1e22f8-7a05-b66b-8825-7d4d97e46dac%40amd.com. >> For more options, visithttps://groups.google.com/d/optout. > > > > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-03-19 13:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-03-18 21:51 [Outreachy kernel] [PATCH] gpu: drm: Use list_first_entry instead of list_entry Arushi Singhal 2018-03-19 9:40 ` [Outreachy kernel] " Christian König 2018-03-19 11:06 ` Julia Lawall 2018-03-19 13:15 ` Christian König 2018-03-19 13:17 ` Fwd: " Christian König
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox