From nobody Thu Dec 14 00:02:47 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SrCGk06Ttz54WS4; Thu, 14 Dec 2023 00:02:54 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SrCGj703Hz4GMk; Thu, 14 Dec 2023 00:02:53 +0000 (UTC) (envelope-from bz@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702512173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UOblTXyep7gynUOvTBDgNZ0mgxYwbMeoO9goGgDabWc=; b=YzfEI0mayNNOy69HqIChcw6Cy5cwhC5IYjDIqOt37tHauC3BYpVvCWobh41WsufhBUFPGP xE9lAq5Ukue1lPLHnL46GEybuTPFUnRHGBjBbTRKg6w31S4Mw1k4dQ2vQ0pJrKOXez0Ufj wiOzJr9g8E3HaMAwh+OtUvs/opdfltL/P+CmBRPqwWc08zQdYVwFRdTBkYffqTD57S9cGG FBtsjDhhEdICBHFGmZptA/d34PQVrl6rnR4U/tfuNzeouYnD6azE8JVq0PLT/q4ZlqoKmd j5TtmfZ9BpW/ulEnCwY4MI4l5QeU8VNh3vPQsV9Srz2DvCdOZQURrxaKtRAvwg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702512173; a=rsa-sha256; cv=none; b=JE2DkBhqlkX6Kt/6MjdtP06FiYOGQ/luCMjZ3wkFtyv4n9pvMVivIV29Xq/q6Xz6bIhq5K L/rQ5VL8+8UeaO/LJzQJO709q/SlT0Ow4BfBlLKm77oWP0vXNzEW8myR+rqH0KbV2Dq6WX +zfy/KWxHEQwul34FY16p+rKnvdw1Tdkup7s2EU2yKy0+/Sg1lFr8WXX1kS7v/76QodQyQ a7MlTL9TiIjQ5r8i5nTxo86cPVNQd9hv939pY0P3GXpJPGIq4xx4sGBJt46GFlYBSk6VO3 gq6JLpfz3zMgcRQWUnlBCYVZqM28InwwFC1+qFQG3UJmcmoShpAsjgbDqMHltg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702512173; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UOblTXyep7gynUOvTBDgNZ0mgxYwbMeoO9goGgDabWc=; b=SRmc19y2LKQDVA7cFcEf6WKu2goXViJAkopfaDllz0fUJxpgJDaghRic8/+1KsFyGHF5ow BRENVLivlZLm3a5IQvc86Tu9T2/k2xRQr/y9O2tpIRoCl+xQk90Ue7mkjePG/hj3D+AQxd 3XIs7ychbbZJqIpXhn0Z4UTJVkD7tAQ131h2blbJnGaHsA2hxWqe6ZK5BU8bpuw3KWxRO9 PNaPXnWomo89jpyNQ6kfFKp7wEeEFrpZsV2xMZ54kMZ02Dmllhbk2XmuUyMielhC7WhUf4 M17XS9o/GqlqvhbdmpI8X/x9BBrXFPxFeaC9shme0A/31akpb5Ynbk+LKZA2qw== Received: from mx1.sbone.de (mx1.sbone.de [IPv6:2a01:4f8:13b:39f::9f:25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mx1.sbone.de", Issuer "SBone.DE Root Certificate Authority" (not verified)) (Authenticated sender: bz/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4SrCGj4qXbz16g; Thu, 14 Dec 2023 00:02:53 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from mail.sbone.de (mail.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:1025]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sbone.de (Postfix) with ESMTPS id 7872F8D4A213; Thu, 14 Dec 2023 00:02:50 +0000 (UTC) Received: from content-filter.t4-02.sbone.de (content-filter.t4-02.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:2742]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPS id 274D92D029D7; Thu, 14 Dec 2023 00:02:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at sbone.de Received: from mail.sbone.de ([IPv6:fde9:577b:c1a9:4902:0:7404:2:1025]) by content-filter.t4-02.sbone.de (content-filter.t4-02.sbone.de [IPv6:fde9:577b:c1a9:4902:0:7404:2:2742]) (amavisd-new, port 10024) with ESMTP id wsKRS1jIHi7G; Thu, 14 Dec 2023 00:02:47 +0000 (UTC) Received: from strong-iwl0.sbone.de (strong-iwl0.sbone.de [IPv6:fde9:577b:c1a9:4902:b66b:fcff:fef3:e3d2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPSA id A7E312D029D2; Thu, 14 Dec 2023 00:02:47 +0000 (UTC) Date: Thu, 14 Dec 2023 00:02:47 +0000 (UTC) From: "Bjoern A. Zeeb" To: =?UTF-8?Q?Jean-S=C3=A9bastienP=C3=A9dron?= cc: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: Re: git: 80446fc7b5e5 - main - linuxkpi: Move `struct kobject` code to `linux_kobject.c` In-Reply-To: <202312131828.3BDISjcm018932@gitrepo.freebsd.org> Message-ID: <1p234o1s-555q-o818-8307-or6n2p874079@SerrOFQ.bet> References: <202312131828.3BDISjcm018932@gitrepo.freebsd.org> X-OpenPGP-Key-Id: 0x14003F198FEFA3E77207EE8D2B58B8F83CCF1842 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1098556516-354143444-1702512167=:54546" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1098556516-354143444-1702512167=:54546 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT On Wed, 13 Dec 2023, Jean-SébastienPédron wrote: > The branch main has been updated by dumbbell: > > URL: https://cgit.FreeBSD.org/src/commit/?id=80446fc7b5e5d22e2bac28bc0474dbe2fec83e43 > > commit 80446fc7b5e5d22e2bac28bc0474dbe2fec83e43 > Author: Jean-Sébastien Pédron > AuthorDate: 2023-12-08 17:58:03 +0000 > Commit: Jean-Sébastien Pédron > CommitDate: 2023-12-13 18:18:46 +0000 > > linuxkpi: Move `struct kobject` code to `linux_kobject.c` > > [Why] > `linux_compat.c` is already too long. I will need to add `struct kset` > in a follow-up commit, so let's move the existing `struct kobject` code > to its own file. > > Reviewed by: manu > Approved by: manu > Differential Revision: https://reviews.freebsd.org/D43019 > --- > sys/compat/linuxkpi/common/include/linux/kobject.h | 2 + > sys/compat/linuxkpi/common/src/linux_compat.c | 190 ------------------ > sys/compat/linuxkpi/common/src/linux_kobject.c | 221 +++++++++++++++++++++ > sys/conf/files | 2 + > sys/modules/linuxkpi/Makefile | 1 + > 5 files changed, 226 insertions(+), 190 deletions(-) > > diff --git a/sys/compat/linuxkpi/common/include/linux/kobject.h b/sys/compat/linuxkpi/common/include/linux/kobject.h > index 6e59e0952d62..06d71faaa873 100644 > --- a/sys/compat/linuxkpi/common/include/linux/kobject.h > +++ b/sys/compat/linuxkpi/common/include/linux/kobject.h > @@ -154,4 +154,6 @@ kobject_uevent_env(struct kobject *kobj, int action, char *envp[]) > */ > } > > +void linux_kobject_kfree_name(struct kobject *kobj); This is not part of the Linux KPI but an internal function? If so this should go into an internal header in the src/ directory? > #endif /* _LINUXKPI_LINUX_KOBJECT_H_ */ > diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c > index b913ae602ab3..a493dc2538ec 100644 > --- a/sys/compat/linuxkpi/common/src/linux_compat.c > +++ b/sys/compat/linuxkpi/common/src/linux_compat.c > @@ -159,176 +159,6 @@ RB_GENERATE(linux_root, rb_node, __entry, panic_cmp); > INTERVAL_TREE_DEFINE(struct interval_tree_node, rb, unsigned long,, START, > LAST,, lkpi_interval_tree) > > -struct kobject * > -kobject_create(void) > -{ > - struct kobject *kobj; > - > - kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); > - if (kobj == NULL) > - return (NULL); > - kobject_init(kobj, &linux_kfree_type); > - > - return (kobj); > -} > - > - > -int > -kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args) > -{ > - va_list tmp_va; > - int len; > - char *old; > - char *name; > - char dummy; > - > - old = kobj->name; > - > - if (old && fmt == NULL) > - return (0); > - > - /* compute length of string */ > - va_copy(tmp_va, args); > - len = vsnprintf(&dummy, 0, fmt, tmp_va); > - va_end(tmp_va); > - > - /* account for zero termination */ > - len++; > - > - /* check for error */ > - if (len < 1) > - return (-EINVAL); > - > - /* allocate memory for string */ > - name = kzalloc(len, GFP_KERNEL); > - if (name == NULL) > - return (-ENOMEM); > - vsnprintf(name, len, fmt, args); > - kobj->name = name; > - > - /* free old string */ > - kfree(old); > - > - /* filter new string */ > - for (; *name != '\0'; name++) > - if (*name == '/') > - *name = '!'; > - return (0); > -} > - > -int > -kobject_set_name(struct kobject *kobj, const char *fmt, ...) > -{ > - va_list args; > - int error; > - > - va_start(args, fmt); > - error = kobject_set_name_vargs(kobj, fmt, args); > - va_end(args); > - > - return (error); > -} > - > -static int > -kobject_add_complete(struct kobject *kobj, struct kobject *parent) > -{ > - const struct kobj_type *t; > - int error; > - > - kobj->parent = parent; > - error = sysfs_create_dir(kobj); > - if (error == 0 && kobj->ktype && kobj->ktype->default_attrs) { > - struct attribute **attr; > - t = kobj->ktype; > - > - for (attr = t->default_attrs; *attr != NULL; attr++) { > - error = sysfs_create_file(kobj, *attr); > - if (error) > - break; > - } > - if (error) > - sysfs_remove_dir(kobj); > - } > - return (error); > -} > - > -int > -kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...) > -{ > - va_list args; > - int error; > - > - va_start(args, fmt); > - error = kobject_set_name_vargs(kobj, fmt, args); > - va_end(args); > - if (error) > - return (error); > - > - return kobject_add_complete(kobj, parent); > -} > - > -void > -linux_kobject_release(struct kref *kref) > -{ > - struct kobject *kobj; > - char *name; > - > - kobj = container_of(kref, struct kobject, kref); > - sysfs_remove_dir(kobj); > - name = kobj->name; > - if (kobj->ktype && kobj->ktype->release) > - kobj->ktype->release(kobj); > - kfree(name); > -} > - > -static void > -linux_kobject_kfree(struct kobject *kobj) > -{ > - kfree(kobj); > -} > - > -static void > -linux_kobject_kfree_name(struct kobject *kobj) > -{ > - if (kobj) { > - kfree(kobj->name); > - } > -} > - > -const struct kobj_type linux_kfree_type = { > - .release = linux_kobject_kfree > -}; > - > -static ssize_t > -lkpi_kobj_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) > -{ > - struct kobj_attribute *ka = > - container_of(attr, struct kobj_attribute, attr); > - > - if (ka->show == NULL) > - return (-EIO); > - > - return (ka->show(kobj, ka, buf)); > -} > - > -static ssize_t > -lkpi_kobj_attr_store(struct kobject *kobj, struct attribute *attr, > - const char *buf, size_t count) > -{ > - struct kobj_attribute *ka = > - container_of(attr, struct kobj_attribute, attr); > - > - if (ka->store == NULL) > - return (-EIO); > - > - return (ka->store(kobj, ka, buf, count)); > -} > - > -const struct sysfs_ops kobj_sysfs_ops = { > - .show = lkpi_kobj_attr_show, > - .store = lkpi_kobj_attr_store, > -}; > - > static void > linux_device_release(struct device *dev) > { > @@ -518,26 +348,6 @@ class_create(struct module *owner, const char *name) > return (class); > } > > -int > -kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype, > - struct kobject *parent, const char *fmt, ...) > -{ > - va_list args; > - int error; > - > - kobject_init(kobj, ktype); > - kobj->ktype = ktype; > - kobj->parent = parent; > - kobj->name = NULL; > - > - va_start(args, fmt); > - error = kobject_set_name_vargs(kobj, fmt, args); > - va_end(args); > - if (error) > - return (error); > - return kobject_add_complete(kobj, parent); > -} > - > static void > linux_kq_lock(void *arg) > { > diff --git a/sys/compat/linuxkpi/common/src/linux_kobject.c b/sys/compat/linuxkpi/common/src/linux_kobject.c > new file mode 100644 > index 000000000000..ddd0a58660f1 > --- /dev/null > +++ b/sys/compat/linuxkpi/common/src/linux_kobject.c > @@ -0,0 +1,221 @@ > +/*- > + * Copyright (c) 2010 Isilon Systems, Inc. > + * Copyright (c) 2010 iX Systems, Inc. > + * Copyright (c) 2010 Panasas, Inc. > + * Copyright (c) 2013-2021 Mellanox Technologies, Ltd. > + * All rights reserved. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice unmodified, this list of conditions, and the following > + * disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR > + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES > + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. > + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, > + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT > + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF > + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +struct kobject * > +kobject_create(void) > +{ > + struct kobject *kobj; > + > + kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); > + if (kobj == NULL) > + return (NULL); > + kobject_init(kobj, &linux_kfree_type); > + > + return (kobj); > +} > + > + > +int > +kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args) > +{ > + va_list tmp_va; > + int len; > + char *old; > + char *name; > + char dummy; > + > + old = kobj->name; > + > + if (old && fmt == NULL) > + return (0); > + > + /* compute length of string */ > + va_copy(tmp_va, args); > + len = vsnprintf(&dummy, 0, fmt, tmp_va); > + va_end(tmp_va); > + > + /* account for zero termination */ > + len++; > + > + /* check for error */ > + if (len < 1) > + return (-EINVAL); > + > + /* allocate memory for string */ > + name = kzalloc(len, GFP_KERNEL); > + if (name == NULL) > + return (-ENOMEM); > + vsnprintf(name, len, fmt, args); > + kobj->name = name; > + > + /* free old string */ > + kfree(old); > + > + /* filter new string */ > + for (; *name != '\0'; name++) > + if (*name == '/') > + *name = '!'; > + return (0); > +} > + > +int > +kobject_set_name(struct kobject *kobj, const char *fmt, ...) > +{ > + va_list args; > + int error; > + > + va_start(args, fmt); > + error = kobject_set_name_vargs(kobj, fmt, args); > + va_end(args); > + > + return (error); > +} > + > +static int > +kobject_add_complete(struct kobject *kobj, struct kobject *parent) > +{ > + const struct kobj_type *t; > + int error; > + > + kobj->parent = parent; > + error = sysfs_create_dir(kobj); > + if (error == 0 && kobj->ktype && kobj->ktype->default_attrs) { > + struct attribute **attr; > + t = kobj->ktype; > + > + for (attr = t->default_attrs; *attr != NULL; attr++) { > + error = sysfs_create_file(kobj, *attr); > + if (error) > + break; > + } > + if (error) > + sysfs_remove_dir(kobj); > + } > + return (error); > +} > + > +int > +kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...) > +{ > + va_list args; > + int error; > + > + va_start(args, fmt); > + error = kobject_set_name_vargs(kobj, fmt, args); > + va_end(args); > + if (error) > + return (error); > + > + return kobject_add_complete(kobj, parent); > +} > + > +int > +kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype, > + struct kobject *parent, const char *fmt, ...) > +{ > + va_list args; > + int error; > + > + kobject_init(kobj, ktype); > + kobj->ktype = ktype; > + kobj->parent = parent; > + kobj->name = NULL; > + > + va_start(args, fmt); > + error = kobject_set_name_vargs(kobj, fmt, args); > + va_end(args); > + if (error) > + return (error); > + return kobject_add_complete(kobj, parent); > +} > + > +void > +linux_kobject_release(struct kref *kref) > +{ > + struct kobject *kobj; > + char *name; > + > + kobj = container_of(kref, struct kobject, kref); > + sysfs_remove_dir(kobj); > + name = kobj->name; > + if (kobj->ktype && kobj->ktype->release) > + kobj->ktype->release(kobj); > + kfree(name); > +} > + > +static void > +linux_kobject_kfree(struct kobject *kobj) > +{ > + kfree(kobj); > +} > + > +const struct kobj_type linux_kfree_type = { > + .release = linux_kobject_kfree > +}; > + > +void > +linux_kobject_kfree_name(struct kobject *kobj) > +{ > + if (kobj) { > + kfree(kobj->name); > + } > +} > + > +static ssize_t > +lkpi_kobj_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) > +{ > + struct kobj_attribute *ka = > + container_of(attr, struct kobj_attribute, attr); > + > + if (ka->show == NULL) > + return (-EIO); > + > + return (ka->show(kobj, ka, buf)); > +} > + > +static ssize_t > +lkpi_kobj_attr_store(struct kobject *kobj, struct attribute *attr, > + const char *buf, size_t count) > +{ > + struct kobj_attribute *ka = > + container_of(attr, struct kobj_attribute, attr); > + > + if (ka->store == NULL) > + return (-EIO); > + > + return (ka->store(kobj, ka, buf, count)); > +} > + > +const struct sysfs_ops kobj_sysfs_ops = { > + .show = lkpi_kobj_attr_show, > + .store = lkpi_kobj_attr_store, > +}; > diff --git a/sys/conf/files b/sys/conf/files > index 377d65926462..bf951d789de3 100644 > --- a/sys/conf/files > +++ b/sys/conf/files > @@ -4567,6 +4567,8 @@ compat/linuxkpi/common/src/linux_i2cbb.c optional compat_linuxkpi \ > compile-with "${LINUXKPI_C}" > compat/linuxkpi/common/src/linux_interrupt.c optional compat_linuxkpi \ > compile-with "${LINUXKPI_C}" > +compat/linuxkpi/common/src/linux_kobject.c optional compat_linuxkpi \ > + compile-with "${LINUXKPI_C}" > compat/linuxkpi/common/src/linux_kthread.c optional compat_linuxkpi \ > compile-with "${LINUXKPI_C}" > compat/linuxkpi/common/src/linux_lock.c optional compat_linuxkpi \ > diff --git a/sys/modules/linuxkpi/Makefile b/sys/modules/linuxkpi/Makefile > index bf40d64de9df..692f69c1f4e1 100644 > --- a/sys/modules/linuxkpi/Makefile > +++ b/sys/modules/linuxkpi/Makefile > @@ -14,6 +14,7 @@ SRCS= linux_compat.c \ > linux_i2c.c \ > linux_i2cbb.c \ > linux_kmod.c \ > + linux_kobject.c \ > linux_kthread.c \ > linux_lock.c \ > linux_netdev.c \ > -- Bjoern A. Zeeb r15:7 --1098556516-354143444-1702512167=:54546--