From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Andrew Jeffery <andrew@codeconstruct.com.au>
Cc: <minyard@acm.org>, <openipmi-developer@lists.sourceforge.net>,
<linux-kernel@vger.kernel.org>, <aladyshev22@gmail.com>,
<jk@codeconstruct.com.au>
Subject: Re: [PATCH 08/10] ipmi: kcs_bmc: Track clients in core
Date: Fri, 3 Nov 2023 15:05:22 +0000 [thread overview]
Message-ID: <20231103150522.00004539@Huawei.com> (raw)
In-Reply-To: <20231103061522.1268637-9-andrew@codeconstruct.com.au>
On Fri, 3 Nov 2023 16:45:20 +1030
Andrew Jeffery <andrew@codeconstruct.com.au> wrote:
> I ran out of spoons before I could come up with a better client tracking
> scheme back in the original refactoring series:
>
> https://lore.kernel.org/all/20210608104757.582199-1-andrew@aj.id.au/
>
> Jonathan prodded Konstantin about the issue in a review of Konstantin's
> MCTP patches[1], prompting an attempt to clean it up.
>
> [1]: https://lore.kernel.org/all/20230929120835.0000108e@Huawei.com/
>
> 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 save
> the client module from further work. The usual container_of() pattern
> gets the client module access to its private data.
>
> Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
Hi Andrew,
A few comments inline.
More generally, whilst this is definitely an improvement I'd have been tempted
to make more use of the linux device model for this with the clients added
as devices with a parent of the kcs_bmc_device. That would then allow for
simple dependency tracking, binding of individual drivers and all that.
What you have here feels fine though and is a much less invasive change.
Jonathan
> 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 {
> +static struct kcs_bmc_client *
> +kcs_bmc_ipmi_add_device(struct kcs_bmc_driver *drv, struct kcs_bmc_device *dev)
> {
> struct kcs_bmc_ipmi *priv;
> int rc;
>
> priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> if (!priv)
> - return -ENOMEM;
> + return ERR_PTR(ENOMEM);
As below. I thought it took negatives..
>
> spin_lock_init(&priv->lock);
> mutex_init(&priv->mutex);
> init_waitqueue_head(&priv->queue);
>
> - priv->client.dev = kcs_bmc;
> - priv->client.ops = &kcs_bmc_ipmi_client_ops;
> + kcs_bmc_client_init(&priv->client, &kcs_bmc_ipmi_client_ops, drv, dev);
>
> priv->miscdev.minor = MISC_DYNAMIC_MINOR;
> - priv->miscdev.name = kasprintf(GFP_KERNEL, "%s%u", DEVICE_NAME, kcs_bmc->channel);
> + priv->miscdev.name = kasprintf(GFP_KERNEL, "%s%u", DEVICE_NAME, dev->channel);
> if (!priv->miscdev.name) {
> rc = -ENOMEM;
ERR_PTR
> goto cleanup_priv;
...
> 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
...
> +static struct kcs_bmc_client *
> +kcs_bmc_serio_add_device(struct kcs_bmc_driver *drv, struct kcs_bmc_device *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)
>
> priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> if (!priv)
> - return -ENOMEM;
> + return ERR_PTR(ENOMEM);
>
> /* Use kzalloc() as the allocation is cleaned up with kfree() via serio_unregister_port() */
> port = kzalloc(sizeof(*port), GFP_KERNEL);
> if (!port) {
> - rc = -ENOMEM;
> + rc = ENOMEM;
Why positive?
Doesn't ERR_PTR() typically get passed negatives?
> goto cleanup_priv;
> }
>
> @@ -88,45 +84,28 @@ static int kcs_bmc_serio_add_device(struct kcs_bmc_device *kcs_bmc)
> port->open = kcs_bmc_serio_open;
> port->close = kcs_bmc_serio_close;
> port->port_data = priv;
> - port->dev.parent = kcs_bmc->dev;
> + port->dev.parent = dev->dev;
>
> spin_lock_init(&priv->lock);
> priv->port = port;
> - priv->client.dev = kcs_bmc;
> - priv->client.ops = &kcs_bmc_serio_client_ops;
>
> - spin_lock_irq(&kcs_bmc_serio_instances_lock);
> - list_add(&priv->entry, &kcs_bmc_serio_instances);
> - spin_unlock_irq(&kcs_bmc_serio_instances_lock);
> + kcs_bmc_client_init(&priv->client, &kcs_bmc_serio_client_ops, drv, dev);
>
> serio_register_port(port);
>
> - pr_info("Initialised serio client for channel %d\n", kcs_bmc->channel);
> + pr_info("Initialised serio client for channel %d\n", dev->channel);
>
> - return 0;
> + return &priv->client;
>
> cleanup_priv:
> kfree(priv);
>
> - return rc;
> + return ERR_PTR(rc);
> }
next prev parent reply other threads:[~2023-11-03 15:05 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 6:15 [PATCH 00/10] ipmi: kcs_bmc: Miscellaneous cleanups Andrew Jeffery
2023-11-03 6:15 ` [PATCH 01/10] ipmi: kcs_bmc: Update module description Andrew Jeffery
2023-11-03 14:34 ` Jonathan Cameron
2023-11-03 6:15 ` [PATCH 02/10] ipmi: kcs_bmc: Include spinlock.h Andrew Jeffery
2023-11-03 14:36 ` Jonathan Cameron
2023-11-05 22:47 ` Andrew Jeffery
2023-11-03 6:15 ` [PATCH 03/10] ipmi: kcs_bmc: Make kcs_bmc_update_event_mask() static Andrew Jeffery
2023-11-03 14:40 ` Jonathan Cameron
2023-11-05 22:52 ` Andrew Jeffery
2023-11-03 6:15 ` [PATCH 04/10] ipmi: kcs_bmc: Make remove_device() callback return void Andrew Jeffery
2023-11-03 14:43 ` Jonathan Cameron
2023-11-05 22:54 ` Andrew Jeffery
2023-11-03 6:15 ` [PATCH 05/10] ipmi: kcs_bmc: Define client actions in terms of kcs_bmc_client Andrew Jeffery
2023-11-03 15:16 ` Jonathan Cameron
2023-11-07 6:32 ` Andrew Jeffery
2023-11-03 6:15 ` [PATCH 06/10] ipmi: kcs_bmc: Integrate buffers into driver struct Andrew Jeffery
2023-11-03 14:45 ` Jonathan Cameron
2023-11-05 22:55 ` Andrew Jeffery
2023-11-03 6:15 ` [PATCH 07/10] ipmi: kcs_bmc: Disassociate client from device lifetimes Andrew Jeffery
2023-11-03 14:51 ` Jonathan Cameron
2023-11-05 23:01 ` Andrew Jeffery
2023-11-03 6:15 ` [PATCH 08/10] ipmi: kcs_bmc: Track clients in core Andrew Jeffery
2023-11-03 15:05 ` Jonathan Cameron [this message]
2023-11-05 23:56 ` Andrew Jeffery
2023-11-20 12:40 ` Jonathan Cameron
2023-11-27 3:02 ` Andrew Jeffery
2023-11-03 6:15 ` [PATCH 09/10] ipmi: kcs_bmc: Add module_kcs_bmc_driver() Andrew Jeffery
2023-11-03 15:06 ` Jonathan Cameron
2023-11-03 6:15 ` [PATCH 10/10] ipmi: kcs_bmc: Add subsystem kerneldoc Andrew Jeffery
2023-11-03 15:12 ` Jonathan Cameron
2023-11-06 0:05 ` Andrew Jeffery
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231103150522.00004539@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=aladyshev22@gmail.com \
--cc=andrew@codeconstruct.com.au \
--cc=jk@codeconstruct.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=minyard@acm.org \
--cc=openipmi-developer@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.