From owner-svn-src-all@freebsd.org Mon May 23 19:03:49 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E5134B4763A; Mon, 23 May 2016 19:03:49 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-ig0-f171.google.com (mail-ig0-f171.google.com [209.85.213.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A8E33188F; Mon, 23 May 2016 19:03:49 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-ig0-f171.google.com with SMTP id c3so5821821igl.0; Mon, 23 May 2016 12:03:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :date:message-id:subject:from:to:cc; bh=vyCqyFRbs/7p1PjvMd31H5vrSYoiYzvVx1ohLJ7VR2E=; b=A5gZJhFQ6aZm/qq0eN3YG9JheFb0kSdzN7y/TAFnoKT4JD05tfGLWN46TaNtT0DTiG HmvtgA24UOTeFcncneQD5c3dur/Mye9uF+6zPOWt3zUvPSrVLP6p4yD5TyH70rFyTSiN A/SX1SPTDw9BQoubTJG6Qj958+XWlKTyZG2WXeThiO8f3OxGgqfP+5sA7PsX+BjxEpKV J2PDKcpF3Vxj5JyRuvlVdlKOWB3Z7lQUJyDRoUO0PeODWx6kDRW0xyKWUQ06qCG7LTuM Oyyj8Xi8+tWUB+FM4aWgZubMp7ko3badCodNuCijZ6jnMc3sPS4teW/9vKizGhdqbhFJ Cpzg== X-Gm-Message-State: AOPr4FV+J6H8sKSJAox1m/4oMBudFtTVc6iV8ND2hSxAI5W0g1wYWo/hKTlxR3pPNt5QeA== X-Received: by 10.50.17.197 with SMTP id q5mr13925989igd.57.1464030222983; Mon, 23 May 2016 12:03:42 -0700 (PDT) Received: from mail-ig0-f173.google.com (mail-ig0-f173.google.com. [209.85.213.173]) by smtp.gmail.com with ESMTPSA id o206sm4182546itg.9.2016.05.23.12.03.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2016 12:03:42 -0700 (PDT) Received: by mail-ig0-f173.google.com with SMTP id fh2so28090479igd.1; Mon, 23 May 2016 12:03:42 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.50.244.180 with SMTP id xh20mr13559857igc.48.1464030222353; Mon, 23 May 2016 12:03:42 -0700 (PDT) Reply-To: cem@FreeBSD.org Received: by 10.36.205.70 with HTTP; Mon, 23 May 2016 12:03:42 -0700 (PDT) In-Reply-To: <201605231203.u4NC3eHI010991@repo.freebsd.org> References: <201605231203.u4NC3eHI010991@repo.freebsd.org> Date: Mon, 23 May 2016 12:03:42 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r300496 - in head/sys/compat/linuxkpi/common: include/linux src From: Conrad Meyer To: Hans Petter Selasky Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2016 19:03:50 -0000 Didn't we already have list_sort in linuxkpi? Maybe I'm confused. On Mon, May 23, 2016 at 5:03 AM, Hans Petter Selasky wrote: > Author: hselasky > Date: Mon May 23 12:03:40 2016 > New Revision: 300496 > URL: https://svnweb.freebsd.org/changeset/base/300496 > > Log: > Add more list_xxx() functions to the LinuxKPI. > > Obtained from: kmacy @ > MFC after: 1 week > Sponsored by: Mellanox Technologies > > Modified: > head/sys/compat/linuxkpi/common/include/linux/list.h > head/sys/compat/linuxkpi/common/src/linux_compat.c > > Modified: head/sys/compat/linuxkpi/common/include/linux/list.h > ============================================================================== > --- head/sys/compat/linuxkpi/common/include/linux/list.h Mon May 23 11:57:23 2016 (r300495) > +++ head/sys/compat/linuxkpi/common/include/linux/list.h Mon May 23 12:03:40 2016 (r300496) > @@ -109,6 +109,13 @@ list_replace(struct list_head *old, stru > } > > static inline void > +list_replace_init(struct list_head *old, struct list_head *new) > +{ > + list_replace(old, new); > + INIT_LIST_HEAD(old); > +} > + > +static inline void > linux_list_add(struct list_head *new, struct list_head *prev, > struct list_head *next) > { > @@ -132,9 +139,18 @@ list_del_init(struct list_head *entry) > #define list_first_entry(ptr, type, member) \ > list_entry((ptr)->next, type, member) > > +#define list_last_entry(ptr, type, member) \ > + list_entry((ptr)->prev, type, member) > + > +#define list_first_entry_or_null(ptr, type, member) \ > + (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL) > + > #define list_next_entry(ptr, member) \ > list_entry(((ptr)->member.next), typeof(*(ptr)), member) > > +#define list_prev_entry(ptr, member) \ > + list_entry(((ptr)->member.prev), typeof(*(ptr)), member) > + > #define list_for_each(p, head) \ > for (p = (head)->next; p != (head); p = (p)->next) > > @@ -436,4 +452,7 @@ static inline int list_is_last(const str > (pos) && ({ n = (pos)->member.next; 1; }); \ > pos = hlist_entry_safe(n, typeof(*(pos)), member)) > > +extern void list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv, > + struct list_head *a, struct list_head *b)); > + > #endif /* _LINUX_LIST_H_ */ > > Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c > ============================================================================== > --- head/sys/compat/linuxkpi/common/src/linux_compat.c Mon May 23 11:57:23 2016 (r300495) > +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Mon May 23 12:03:40 2016 (r300496) > @@ -72,6 +72,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > > #include > > @@ -1358,6 +1359,47 @@ unregister_inetaddr_notifier(struct noti > return (0); > } > > +struct list_sort_thunk { > + int (*cmp)(void *, struct list_head *, struct list_head *); > + void *priv; > +}; > + > +static inline int > +linux_le_cmp(void *priv, const void *d1, const void *d2) > +{ > + struct list_head *le1, *le2; > + struct list_sort_thunk *thunk; > + > + thunk = priv; > + le1 = *(__DECONST(struct list_head **, d1)); > + le2 = *(__DECONST(struct list_head **, d2)); > + return ((thunk->cmp)(thunk->priv, le1, le2)); > +} > + > +void > +list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv, > + struct list_head *a, struct list_head *b)) > +{ > + struct list_sort_thunk thunk; > + struct list_head **ar, *le; > + size_t count, i; > + > + count = 0; > + list_for_each(le, head) > + count++; > + ar = malloc(sizeof(struct list_head *) * count, M_KMALLOC, M_WAITOK); > + i = 0; > + list_for_each(le, head) > + ar[i++] = le; > + thunk.cmp = cmp; > + thunk.priv = priv; > + qsort_r(ar, count, sizeof(struct list_head *), &thunk, linux_le_cmp); > + INIT_LIST_HEAD(head); > + for (i = 0; i < count; i++) > + list_add_tail(ar[i], head); > + free(ar, M_KMALLOC); > +} > + > void > linux_irq_handler(void *ent) > { >