From patchwork Fri Nov 11 11:43:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 9422765 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 73276601C0 for ; Fri, 11 Nov 2016 11:44:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6427929A75 for ; Fri, 11 Nov 2016 11:44:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 580E329A78; Fri, 11 Nov 2016 11:44:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7CA829A75 for ; Fri, 11 Nov 2016 11:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750714AbcKKLoJ (ORCPT ); Fri, 11 Nov 2016 06:44:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59590 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755999AbcKKLmi (ORCPT ); Fri, 11 Nov 2016 06:42:38 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0ECA661E5B; Fri, 11 Nov 2016 11:42:38 +0000 (UTC) Received: from astarta.redhat.com (vpn1-4-204.ams2.redhat.com [10.36.4.204]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uABBgPQa019017 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 11 Nov 2016 06:42:36 -0500 From: Yauheni Kaliuta To: linux-modules@vger.kernel.org Cc: Mian Yousaf Kaukab , bjorn.andersson@linaro.org, Jessica Yu Subject: [PATCH RFC 2/3] libkmod: list: export list handling functions Date: Fri, 11 Nov 2016 13:43:20 +0200 Message-Id: <1478864601-3259-3-git-send-email-yauheni.kaliuta@redhat.com> In-Reply-To: <1478864601-3259-1-git-send-email-yauheni.kaliuta@redhat.com> References: <1478683053.4155.8.camel@suse.com> <1478864601-3259-1-git-send-email-yauheni.kaliuta@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 11 Nov 2016 11:42:38 +0000 (UTC) Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The library uses list functions to create lists internally and provides to the clients immutable lists and only functions to traverse them. It may be useful to create own lists in the kmod utilities, so export functions for lists creation as well (as it's done for arrays). The following functions affected (needed for the following depmod modifications): kmod_list_append() kmod_list_remove() kmod_list_remove_data() The patch also adds kmod_list_data() accessor to keep the struct kmod_list opaque. Signed-off-by: Yauheni Kaliuta --- libkmod/libkmod-internal.h | 4 ---- libkmod/libkmod-list.c | 36 ++++++++++++++++++++++++++++++++++-- libkmod/libkmod.h | 5 +++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h index 4d9db6bc7845..fd1eaed6f556 100644 --- a/libkmod/libkmod-internal.h +++ b/libkmod/libkmod-internal.h @@ -59,11 +59,7 @@ struct kmod_list { void *data; }; -struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2))); struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) _must_check_ __attribute__((nonnull(2))); -struct kmod_list *kmod_list_remove(struct kmod_list *list) _must_check_; -struct kmod_list *kmod_list_remove_data(struct kmod_list *list, - const void *data) _must_check_ __attribute__((nonnull(2))); struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, unsigned int n) _must_check_; struct kmod_list *kmod_list_insert_after(struct kmod_list *list, const void *data) __attribute__((nonnull(2))); diff --git a/libkmod/libkmod-list.c b/libkmod/libkmod-list.c index 7623693ac12e..8dd445e9829a 100644 --- a/libkmod/libkmod-list.c +++ b/libkmod/libkmod-list.c @@ -186,7 +186,15 @@ struct kmod_list *kmod_list_prepend(struct kmod_list *list, const void *data) return new; } -struct kmod_list *kmod_list_remove(struct kmod_list *list) +/** + * kmod_list_remove: + * @list: the element of the list to remove + * + * Removes and frees the element @list from the list it is a member of. + * + * Returns: the new list head value. + */ +KMOD_EXPORT struct kmod_list *kmod_list_remove(struct kmod_list *list) { struct list_node *node; @@ -202,7 +210,17 @@ struct kmod_list *kmod_list_remove(struct kmod_list *list) return container_of(node, struct kmod_list, node); } -struct kmod_list *kmod_list_remove_data(struct kmod_list *list, +/** + * kmod_list_remove_data: + * @list: the head of the list + * @data: pointer to the data element to remove + * + * Gets the list head @list, searches for an entry, contaning + * data pointer @data and if finds, removes the element from the list. + * + * Returns: the new list head value. + */ +KMOD_EXPORT struct kmod_list *kmod_list_remove_data(struct kmod_list *list, const void *data) { struct kmod_list *itr; @@ -312,3 +330,17 @@ KMOD_EXPORT struct kmod_list *kmod_list_last(const struct kmod_list *list) return NULL; return container_of(list->node.prev, struct kmod_list, node); } + +/** + * kmod_list_data: + * @list: list element to extract data pointer from + * + * Returns the @data pointer from the list entry + * to keep the kmod_list structure opaque + */ +KMOD_EXPORT void *kmod_list_data(const struct kmod_list *list) +{ + if (list == NULL) + return NULL; + return list->data; +} diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index f9e33c6cde90..a720236dd353 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -87,6 +87,11 @@ struct kmod_list *kmod_list_next(const struct kmod_list *list, struct kmod_list *kmod_list_prev(const struct kmod_list *list, const struct kmod_list *curr); struct kmod_list *kmod_list_last(const struct kmod_list *list); +struct kmod_list *kmod_list_append(struct kmod_list *list, const void *data) __attribute__((warn_unused_result)) __attribute__((nonnull(2))); +struct kmod_list *kmod_list_remove(struct kmod_list *list) __attribute__((warn_unused_result)); +struct kmod_list *kmod_list_remove_data(struct kmod_list *list, + const void *data) __attribute__((warn_unused_result)) __attribute__((nonnull(2))); +void *kmod_list_data(const struct kmod_list *list); #define kmod_list_foreach(list_entry, first_entry) \ for (list_entry = first_entry; \