[PATCH v2 1/9] list: add list_last_entry_or_null()

Luca Ceresoli posted 9 patches 2 months ago
[PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Luca Ceresoli 2 months ago
Add an equivalent of list_first_entry_or_null() to obtain the last element
of a list.

Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

---

Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Zijun Hu <quic_zijuhu@quicinc.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 include/linux/list.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/list.h b/include/linux/list.h
index e7e28afd28f8eef94ab6baec77e69ea104ba0391..7f7657e416209a2941b3f292b1334e9e0f2a3ca5 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -636,6 +636,20 @@ static inline void list_splice_tail_init(struct list_head *list,
 	pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
 })
 
+/**
+ * list_last_entry_or_null - get the last element from a list
+ * @ptr:	the list head to take the element from.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the list_head within the struct.
+ *
+ * Note that if the list is empty, it returns NULL.
+ */
+#define list_last_entry_or_null(ptr, type, member) ({ \
+	struct list_head *head__ = (ptr); \
+	struct list_head *pos__ = READ_ONCE(head__->prev); \
+	pos__ != head__ ? list_entry(pos__, type, member) : NULL; \
+})
+
 /**
  * list_next_entry - get the next element in list
  * @pos:	the type * to cursor

-- 
2.50.1
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Andy Shevchenko 2 months ago
On Fri, Aug 01, 2025 at 07:05:23PM +0200, Luca Ceresoli wrote:
> Add an equivalent of list_first_entry_or_null() to obtain the last element
> of a list.

Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Luca Ceresoli 1 month, 3 weeks ago
Hello relevant maintainers,

On Wed, 6 Aug 2025 00:55:02 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Fri, Aug 01, 2025 at 07:05:23PM +0200, Luca Ceresoli wrote:
> > Add an equivalent of list_first_entry_or_null() to obtain the last element
> > of a list.  
> 
> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks Andy!

However I'm not sure when and where this should be applied.

Except for this one patch, all patches in the series are for
drm-misc-next. Also, patch 1 is currently not needed by any other
series AFAIK.

Based on the above, is it correct to assume that the whole series can
be applied on drm-misc-next? (when other patches will have a
R-by/Ack-by of course)

Also, is Andy's A-by enough to apply this patch?

Best regards,
Luca

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Andy Shevchenko 1 month, 2 weeks ago
On Thu, Aug 14, 2025 at 06:36:09PM +0200, Luca Ceresoli wrote:
> On Wed, 6 Aug 2025 00:55:02 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > On Fri, Aug 01, 2025 at 07:05:23PM +0200, Luca Ceresoli wrote:
> > > Add an equivalent of list_first_entry_or_null() to obtain the last element
> > > of a list.  
> > 
> > Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Thanks Andy!
> 
> However I'm not sure when and where this should be applied.
> 
> Except for this one patch, all patches in the series are for
> drm-misc-next. Also, patch 1 is currently not needed by any other
> series AFAIK.
> 
> Based on the above, is it correct to assume that the whole series can
> be applied on drm-misc-next? (when other patches will have a
> R-by/Ack-by of course)
> 
> Also, is Andy's A-by enough to apply this patch?

The list.h is common for many, I think going via DRM with my Ack is enough
based on the Git history of my changes in this file. But if you want more
reliable source, get an Ack from Andrew Morton.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Luca Ceresoli 1 month ago
Hello DRM maintainers,

On Wed, 20 Aug 2025 16:43:56 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Thu, Aug 14, 2025 at 06:36:09PM +0200, Luca Ceresoli wrote:
> > On Wed, 6 Aug 2025 00:55:02 +0300
> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> >   
> > > On Fri, Aug 01, 2025 at 07:05:23PM +0200, Luca Ceresoli wrote:  
> > > > Add an equivalent of list_first_entry_or_null() to obtain the last element
> > > > of a list.    
> > > 
> > > Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>  
> > 
> > Thanks Andy!
> > 
> > However I'm not sure when and where this should be applied.
> > 
> > Except for this one patch, all patches in the series are for
> > drm-misc-next. Also, patch 1 is currently not needed by any other
> > series AFAIK.
> > 
> > Based on the above, is it correct to assume that the whole series can
> > be applied on drm-misc-next? (when other patches will have a
> > R-by/Ack-by of course)
> > 
> > Also, is Andy's A-by enough to apply this patch?  
> 
> The list.h is common for many, I think going via DRM with my Ack is enough
> based on the Git history of my changes in this file. But if you want more
> reliable source, get an Ack from Andrew Morton.

While applying this patch with dim on drm-misc-next, dim push-branch
failed because:

  dim: ERROR: cb86408b1fc2 ("list: add list_last_entry_or_null()"): Mandatory Maintainer Acked-by missing., aborting

Looking at the dim code, it is looking for a Reviewed- or Acked-by from
people listed by `scripts/get_maintainer.pl --no-git-fallback -m --nol
--norolestats`. but that command returns an empty string, so it will
never allow me to push.

How can I get that commit pushed to drm-misc-next?

I think `dim push-branch -f` would work: am I supposed to use it?

(not sure my committer rights allow that)

Luca

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Maxime Ripard 1 month ago
On Tue, Sep 02, 2025 at 01:57:09PM +0200, Luca Ceresoli wrote:
> Hello DRM maintainers,
> 
> On Wed, 20 Aug 2025 16:43:56 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > On Thu, Aug 14, 2025 at 06:36:09PM +0200, Luca Ceresoli wrote:
> > > On Wed, 6 Aug 2025 00:55:02 +0300
> > > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > >   
> > > > On Fri, Aug 01, 2025 at 07:05:23PM +0200, Luca Ceresoli wrote:  
> > > > > Add an equivalent of list_first_entry_or_null() to obtain the last element
> > > > > of a list.    
> > > > 
> > > > Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>  
> > > 
> > > Thanks Andy!
> > > 
> > > However I'm not sure when and where this should be applied.
> > > 
> > > Except for this one patch, all patches in the series are for
> > > drm-misc-next. Also, patch 1 is currently not needed by any other
> > > series AFAIK.
> > > 
> > > Based on the above, is it correct to assume that the whole series can
> > > be applied on drm-misc-next? (when other patches will have a
> > > R-by/Ack-by of course)
> > > 
> > > Also, is Andy's A-by enough to apply this patch?  
> > 
> > The list.h is common for many, I think going via DRM with my Ack is enough
> > based on the Git history of my changes in this file. But if you want more
> > reliable source, get an Ack from Andrew Morton.
> 
> While applying this patch with dim on drm-misc-next, dim push-branch
> failed because:
> 
>   dim: ERROR: cb86408b1fc2 ("list: add list_last_entry_or_null()"): Mandatory Maintainer Acked-by missing., aborting
> 
> Looking at the dim code, it is looking for a Reviewed- or Acked-by from
> people listed by `scripts/get_maintainer.pl --no-git-fallback -m --nol
> --norolestats`. but that command returns an empty string, so it will
> never allow me to push.
> 
> How can I get that commit pushed to drm-misc-next?

Adding a MAINTAINERS entry for it would be nice too

Maxime
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Andy Shevchenko 1 month ago
On Tue, Sep 02, 2025 at 02:22:28PM +0200, Maxime Ripard wrote:
> On Tue, Sep 02, 2025 at 01:57:09PM +0200, Luca Ceresoli wrote:
> > On Wed, 20 Aug 2025 16:43:56 +0300
> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

...

> > While applying this patch with dim on drm-misc-next, dim push-branch
> > failed because:
> > 
> >   dim: ERROR: cb86408b1fc2 ("list: add list_last_entry_or_null()"): Mandatory Maintainer Acked-by missing., aborting
> > 
> > Looking at the dim code, it is looking for a Reviewed- or Acked-by from
> > people listed by `scripts/get_maintainer.pl --no-git-fallback -m --nol
> > --norolestats`. but that command returns an empty string, so it will
> > never allow me to push.

This seems to be a quite strict rule, esp. for the include/* lib/* code.
I believe among DRM reviewers / maintainers a lot of people capable to
review that code and push it. Why is it a problem?

> > How can I get that commit pushed to drm-misc-next?
> 
> Adding a MAINTAINERS entry for it would be nice too

Just in case you want to go this direction, please, do not put my name as M:.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Jani Nikula 1 month ago
On Tue, 02 Sep 2025, Luca Ceresoli <luca.ceresoli@bootlin.com> wrote:
> Hello DRM maintainers,
>
> On Wed, 20 Aug 2025 16:43:56 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
>> On Thu, Aug 14, 2025 at 06:36:09PM +0200, Luca Ceresoli wrote:
>> > On Wed, 6 Aug 2025 00:55:02 +0300
>> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>> >   
>> > > On Fri, Aug 01, 2025 at 07:05:23PM +0200, Luca Ceresoli wrote:  
>> > > > Add an equivalent of list_first_entry_or_null() to obtain the last element
>> > > > of a list.    
>> > > 
>> > > Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>  
>> > 
>> > Thanks Andy!
>> > 
>> > However I'm not sure when and where this should be applied.
>> > 
>> > Except for this one patch, all patches in the series are for
>> > drm-misc-next. Also, patch 1 is currently not needed by any other
>> > series AFAIK.
>> > 
>> > Based on the above, is it correct to assume that the whole series can
>> > be applied on drm-misc-next? (when other patches will have a
>> > R-by/Ack-by of course)
>> > 
>> > Also, is Andy's A-by enough to apply this patch?  
>> 
>> The list.h is common for many, I think going via DRM with my Ack is enough
>> based on the Git history of my changes in this file. But if you want more
>> reliable source, get an Ack from Andrew Morton.
>
> While applying this patch with dim on drm-misc-next, dim push-branch
> failed because:
>
>   dim: ERROR: cb86408b1fc2 ("list: add list_last_entry_or_null()"): Mandatory Maintainer Acked-by missing., aborting
>
> Looking at the dim code, it is looking for a Reviewed- or Acked-by from
> people listed by `scripts/get_maintainer.pl --no-git-fallback -m --nol
> --norolestats`. but that command returns an empty string, so it will
> never allow me to push.
>
> How can I get that commit pushed to drm-misc-next?
>
> I think `dim push-branch -f` would work: am I supposed to use it?

Try 'dim -f push-branch'. The parameters after push-branch go to git,
and you don't want that.

BR,
Jani.

>
> (not sure my committer rights allow that)
>
> Luca

-- 
Jani Nikula, Intel
Re: [PATCH v2 1/9] list: add list_last_entry_or_null()
Posted by Luca Ceresoli 1 month ago
Hello Jani,

On Tue, 02 Sep 2025 15:10:14 +0300
Jani Nikula <jani.nikula@linux.intel.com> wrote:

> > While applying this patch with dim on drm-misc-next, dim push-branch
> > failed because:
> >
> >   dim: ERROR: cb86408b1fc2 ("list: add list_last_entry_or_null()"): Mandatory Maintainer Acked-by missing., aborting
> >
> > Looking at the dim code, it is looking for a Reviewed- or Acked-by from
> > people listed by `scripts/get_maintainer.pl --no-git-fallback -m --nol
> > --norolestats`. but that command returns an empty string, so it will
> > never allow me to push.
> >
> > How can I get that commit pushed to drm-misc-next?
> >
> > I think `dim push-branch -f` would work: am I supposed to use it?  
> 
> Try 'dim -f push-branch'. The parameters after push-branch go to git,
> and you don't want that.

Done, thanks for the quick reply!

Luca

-- 
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com