Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1819547rdf; Sun, 5 Nov 2023 16:02:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgYp2iO3ImhhPX60wDDZ6NBruoaVykcp8uywSWwDVtJG0skh40fVMBSDBa6iTpOqq+K+6p X-Received: by 2002:a05:6870:61ce:b0:1e9:b08d:69f0 with SMTP id b14-20020a05687061ce00b001e9b08d69f0mr26442083oah.51.1699228978635; Sun, 05 Nov 2023 16:02:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699228978; cv=none; d=google.com; s=arc-20160816; b=Ml1NJFqp4HMUxKTKymzu9RyhybKdfWMH5nvhvuQXsyMF0284FRyo1saxmvVYnUsbIe kUqa8zORmv28CylewyZUjtp/hssac/6Kyo6Ktr4UVDS50J8wkItXk8EK6Ybk6XAML3L1 jqbDEwhvBzfkW34op5zXNKSdnAX7/uRCmuBgsSTiCQYts3g9PWs5RNj+SCDl1ZMjcL+E yXJsuxJbd0z40IBWw6+Gjp51b3V/oECWub4k5HlYh60CpXGy02EKQN/EdajaqfpfvVxa U/Oyb+1Pe2MPEAwRP7uozr49ijj/b67WNaZikBB1EBAW3y3J7fN5xOdnGefsAXIHc7pX a/Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=QFNVMP6dED+kPw+11hk5uky5JXNxNuLL67bKcqe7dkE=; fh=MQKibY1gp03oHfoDc5Rz7YuTEvyytF8k3oA40d6PJLM=; b=0KHMEpQjiJx28L68L9aNfr+lmE+HUoBQmg1vdEr85EUCTeAA5u4KVapnm5pKawEGP+ M5nGgaYDUhfeIkbsEF3uUiV+bUubnpcQXB7GGuK9oe7UZnrjKETptGRvt9Py6EeO7qfc 0e5AKI27jlz4xIFvwox/2GIIIjhty4n9QKjveCxSv8mH8whsr2lIkD3NQ92e8ZpbrzbL MnCMIHV/t+hQUcBR1dzlo6pqAV8sESjjUWF7FeO6+3SEIqlIuOmiUDkRMD3OOpfrP+Y4 FegUkl371xK++tG8Lhdqv6HZoi7hxK7oHdUN6B30OWtOGCzt4L5I1B/O8OjX5WWqGTgb YEPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeconstruct.com.au header.s=2022a header.b=JM1hi779; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id bg17-20020a056a02011100b00565eb0b4f33si7822918pgb.224.2023.11.05.16.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 16:02:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@codeconstruct.com.au header.s=2022a header.b=JM1hi779; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeconstruct.com.au Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id AA512807782C; Sun, 5 Nov 2023 16:02:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbjKEX4r (ORCPT + 99 others); Sun, 5 Nov 2023 18:56:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjKEX4q (ORCPT ); Sun, 5 Nov 2023 18:56:46 -0500 Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F457C6 for ; Sun, 5 Nov 2023 15:56:42 -0800 (PST) Received: from [192.168.68.112] (ppp14-2-79-67.adl-apt-pir-bras31.tpg.internode.on.net [14.2.79.67]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id EEADE20075; Mon, 6 Nov 2023 07:56:39 +0800 (AWST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codeconstruct.com.au; s=2022a; t=1699228600; bh=QFNVMP6dED+kPw+11hk5uky5JXNxNuLL67bKcqe7dkE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=JM1hi779FDp/H7CCa8PanzJEXg14a9Ih5wIprldlHEc0w5UI1xseI8qlypTuIh6Qq AS0XCUdifw4EeBqhBcpPoteGUDxapoagwwB50E4QH6ksDPYgzzLcK47pHpdQzwjr+2 QxQbKavAlwUvv5x0jfQLl+d9YXv9Yj0DykbV38h2za3H/QDUVwFjPDNOxIwxhvlFY1 8SFEBqm8hkTzbjGGi0QOA2DfFoTzDckHwiKDkR7PH7NHA0wRBc0KcaoSoJCkrJW2c1 zJ1ZJOBqrrCDe1rvsrLtK+IP0MgtVq3ylBjzieUhyX8FZdsq/OJHWmlEwQTxMmArpX j2VS3dp1vFsAA== Message-ID: Subject: Re: [PATCH 08/10] ipmi: kcs_bmc: Track clients in core From: Andrew Jeffery To: Jonathan Cameron Cc: minyard@acm.org, openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, aladyshev22@gmail.com, jk@codeconstruct.com.au Date: Mon, 06 Nov 2023 10:26:38 +1030 In-Reply-To: <20231103150522.00004539@Huawei.com> References: <20231103061522.1268637-1-andrew@codeconstruct.com.au> <20231103061522.1268637-9-andrew@codeconstruct.com.au> <20231103150522.00004539@Huawei.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Sun, 05 Nov 2023 16:02:55 -0800 (PST) On Fri, 2023-11-03 at 15:05 +0000, Jonathan Cameron wrote: > On Fri, 3 Nov 2023 16:45:20 +1030 > Andrew Jeffery wrote: >=20 > > I ran out of spoons before I could come up with a better client trackin= g > > scheme back in the original refactoring series: > >=20 > > https://lore.kernel.org/all/20210608104757.582199-1-andrew@aj.id.au/ > >=20 > > Jonathan prodded Konstantin about the issue in a review of Konstantin's > > MCTP patches[1], prompting an attempt to clean it up. > >=20 > > [1]: https://lore.kernel.org/all/20230929120835.0000108e@Huawei.com/ > >=20 > > Prevent client modules from having to track their own instances by > > requiring they return a pointer to a client object from their > > add_device() implementation. We can then track this in the core, and > > provide it as the argument to the remove_device() implementation to sav= e > > the client module from further work. The usual container_of() pattern > > gets the client module access to its private data. > >=20 > > Signed-off-by: Andrew Jeffery >=20 > Hi Andrew, >=20 > A few comments inline. > More generally, whilst this is definitely an improvement I'd have been te= mpted > to make more use of the linux device model for this with the clients adde= d > as devices with a parent of the kcs_bmc_device. That would then allow fo= r > simple dependency tracking, binding of individual drivers and all that. >=20 > What you have here feels fine though and is a much less invasive change. Yeah, I had this debate with myself before posting the patches. My reasoning for the current approach is that the clients don't typically represent a device, rather a protocol implementation that is communicated over a KCS device (maybe more like pairing a line discipline with a UART). It was unclear to me whether associating a `struct device` with a protocol implementation was stretching the abstraction a bit, or whether I haven't considered some other perspective hard enough - maybe we treat the client as the remote device, similar to e.g. a `struct i2c_client`? >=20 > Jonathan >=20 >=20 > > diff --git a/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c b/drivers/char/ipmi/= kcs_bmc_cdev_ipmi.c > > index 98f231f24c26..9fca31f8c7c2 100644 > > --- a/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c > > +++ b/drivers/char/ipmi/kcs_bmc_cdev_ipmi.c > > @@ -71,8 +71,6 @@ enum kcs_ipmi_errors { >=20 >=20 >=20 > > +static struct kcs_bmc_client * > > +kcs_bmc_ipmi_add_device(struct kcs_bmc_driver *drv, struct kcs_bmc_dev= ice *dev) > > { > > struct kcs_bmc_ipmi *priv; > > int rc; > > =20 > > priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); > > if (!priv) > > - return -ENOMEM; > > + return ERR_PTR(ENOMEM); > As below. I thought it took negatives.. I should have double checked that. It requires negatives. Thanks. > > =20 > > spin_lock_init(&priv->lock); > > mutex_init(&priv->mutex); > > init_waitqueue_head(&priv->queue); > > =20 > > - priv->client.dev =3D kcs_bmc; > > - priv->client.ops =3D &kcs_bmc_ipmi_client_ops; > > + kcs_bmc_client_init(&priv->client, &kcs_bmc_ipmi_client_ops, drv, dev= ); > > =20 > > priv->miscdev.minor =3D MISC_DYNAMIC_MINOR; > > - priv->miscdev.name =3D kasprintf(GFP_KERNEL, "%s%u", DEVICE_NAME, kcs= _bmc->channel); > > + priv->miscdev.name =3D kasprintf(GFP_KERNEL, "%s%u", DEVICE_NAME, dev= ->channel); > > if (!priv->miscdev.name) { > > rc =3D -ENOMEM; > ERR_PTR I converted it to an ERR_PTR in the return after the cleanup_priv label. Maybe it's preferable I do the conversion immediately? Easy enough to change if you think so. > > goto cleanup_priv; >=20 >=20 >=20 > ... >=20 > > diff --git a/drivers/char/ipmi/kcs_bmc_serio.c b/drivers/char/ipmi/kcs_= bmc_serio.c > > index 0a68c76da955..3cfda39506f6 100644 > > --- a/drivers/char/ipmi/kcs_bmc_serio.c > > +++ b/drivers/char/ipmi/kcs_bmc_serio.c >=20 > ... >=20 >=20 > > +static struct kcs_bmc_client * > > +kcs_bmc_serio_add_device(struct kcs_bmc_driver *drv, struct kcs_bmc_de= vice *dev) > > { > > struct kcs_bmc_serio *priv; > > struct serio *port; > > @@ -75,12 +71,12 @@ static int kcs_bmc_serio_add_device(struct kcs_bmc_= device *kcs_bmc) > > =20 > > priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); > > if (!priv) > > - return -ENOMEM; > > + return ERR_PTR(ENOMEM); > > =20 > > /* Use kzalloc() as the allocation is cleaned up with kfree() via ser= io_unregister_port() */ > > port =3D kzalloc(sizeof(*port), GFP_KERNEL); > > if (!port) { > > - rc =3D -ENOMEM; > > + rc =3D ENOMEM; > Why positive? > Doesn't ERR_PTR() typically get passed negatives?=20 Ack, as above. Thanks for the review, Andrew