From nobody Sun Feb 8 16:31:31 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21DE81D9A49 for ; Mon, 2 Dec 2024 16:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157338; cv=none; b=SgSkqnKgceJPUplWmXAiOTKfVgWEOCLusue4YryKLQawTnG2WVbUQxyY1Vp0bDfXvblE6RIm+7fbyI/RwVf00AeBabvR8sR3e7gAmmD+gVj9NBLAMLidWdwQDJzaJEdvGDUmpynmmMQDOb0VlbBxpiFUzZU8nuUPosdfU4hvjAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157338; c=relaxed/simple; bh=u5EZ3YXXyHexgLkIWg37zxTtxHQw3PG7Q+9cwmf73OQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ep1IPgw5aOn1seCLMqoPb9/CBHu7MutDHJiLCfdBGf4m1W+SL1q/P6yz7uhZH37GiP7OWg8dlZAU7iuxWrjn7o25Ie1rB1bXNu/SoVI5nmhnVJQWmJ/4TW2OdDdanLwNwXNvJNdnuBt7/imnUaDJhE6Mc8tTC1vLyevYzepAFRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CPIf59n8; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CPIf59n8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733157335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SEJ7H/yOFS9JfCvCRitFDUty7z4REjR6o2/XyEG16Ng=; b=CPIf59n8Ot3TFN9Jg0+CkotzIiovl6v37vym8gQO5ZXJL5WQIEYtgGEaaHWBM9LmZ0GlAh jgiSnQQxkXfTDyUYO8c8yQbXxxltFkdajRFFfv+MbOEes68WXxrC+1mseFpmUlOyyyG+Wa HNI26f+ulaA6LuHjlAR3SRuaimKn1rc= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-583-xA20c_HUOo6XJGacWk1l_g-1; Mon, 02 Dec 2024 11:35:31 -0500 X-MC-Unique: xA20c_HUOo6XJGacWk1l_g-1 X-Mimecast-MFC-AGG-ID: xA20c_HUOo6XJGacWk1l_g Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 22826195608A; Mon, 2 Dec 2024 16:35:29 +0000 (UTC) Received: from rhel-developer-toolbox-2.redhat.com (unknown [10.45.225.22]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 342121956089; Mon, 2 Dec 2024 16:35:24 +0000 (UTC) From: Michal Schmidt To: Rodolfo Giometti Cc: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Greg Kroah-Hartman , Christophe JAILLET , "Dr. David Alan Gilbert" , Ma Ke , Andrew Morton , George Spelvin , linux-kernel@vger.kernel.org Subject: [PATCH 5/6] pps: embed "dev" in the pps_device Date: Mon, 2 Dec 2024 17:34:50 +0100 Message-ID: <20241202163451.1442566-6-mschmidt@redhat.com> In-Reply-To: <20241202163451.1442566-1-mschmidt@redhat.com> References: <20241202163451.1442566-1-mschmidt@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Type: text/plain; charset="utf-8" Embed the struct device directly in struct pps_device. Use device_initialize() + device_add() instead of device_create(). Advantages: Avoids a separate allocation. Lets us set dev as cdev's parent without the extra get_device() hack. Signed-off-by: Michal Schmidt --- drivers/pps/clients/pps-gpio.c | 2 +- drivers/pps/clients/pps-ldisc.c | 6 +-- drivers/pps/clients/pps_parport.c | 4 +- drivers/pps/kapi.c | 10 ++--- drivers/pps/pps.c | 61 +++++++++++++++---------------- include/linux/pps_kernel.h | 2 +- 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c index 791fdc9326dd..a21bf56e7a87 100644 --- a/drivers/pps/clients/pps-gpio.c +++ b/drivers/pps/clients/pps-gpio.c @@ -214,7 +214,7 @@ static int pps_gpio_probe(struct platform_device *pdev) return -EINVAL; } =20 - dev_info(data->pps->dev, "Registered IRQ %d as PPS source\n", + dev_info(&data->pps->dev, "Registered IRQ %d as PPS source\n", data->irq); =20 return 0; diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldis= c.c index 443d6bae19d1..49ae33cca03d 100644 --- a/drivers/pps/clients/pps-ldisc.c +++ b/drivers/pps/clients/pps-ldisc.c @@ -32,7 +32,7 @@ static void pps_tty_dcd_change(struct tty_struct *tty, bo= ol active) pps_event(pps, &ts, active ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR, NULL); =20 - dev_dbg(pps->dev, "PPS %s at %lu\n", + dev_dbg(&pps->dev, "PPS %s at %lu\n", active ? "assert" : "clear", jiffies); } =20 @@ -69,7 +69,7 @@ static int pps_tty_open(struct tty_struct *tty) goto err_unregister; } =20 - dev_info(pps->dev, "source \"%s\" added\n", info.path); + dev_info(&pps->dev, "source \"%s\" added\n", info.path); =20 return 0; =20 @@ -89,7 +89,7 @@ static void pps_tty_close(struct tty_struct *tty) if (WARN_ON(!pps)) return; =20 - dev_info(pps->dev, "removed\n"); + dev_info(&pps->dev, "removed\n"); pps_unregister_source(pps); } =20 diff --git a/drivers/pps/clients/pps_parport.c b/drivers/pps/clients/pps_pa= rport.c index abaffb4e1c1c..24db06750297 100644 --- a/drivers/pps/clients/pps_parport.c +++ b/drivers/pps/clients/pps_parport.c @@ -81,7 +81,7 @@ static void parport_irq(void *handle) /* check the signal (no signal means the pulse is lost this time) */ if (!signal_is_set(port)) { local_irq_restore(flags); - dev_err(dev->pps->dev, "lost the signal\n"); + dev_err(&dev->pps->dev, "lost the signal\n"); goto out_assert; } =20 @@ -98,7 +98,7 @@ static void parport_irq(void *handle) /* timeout */ dev->cw_err++; if (dev->cw_err >=3D CLEAR_WAIT_MAX_ERRORS) { - dev_err(dev->pps->dev, "disabled clear edge capture after %d" + dev_err(&dev->pps->dev, "disabled clear edge capture after %d" " timeouts\n", dev->cw_err); dev->cw =3D 0; dev->cw_err =3D 0; diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c index d9d566f70ed1..a76685c147ee 100644 --- a/drivers/pps/kapi.c +++ b/drivers/pps/kapi.c @@ -41,7 +41,7 @@ static void pps_add_offset(struct pps_ktime *ts, struct p= ps_ktime *offset) static void pps_echo_client_default(struct pps_device *pps, int event, void *data) { - dev_info(pps->dev, "echo %s %s\n", + dev_info(&pps->dev, "echo %s %s\n", event & PPS_CAPTUREASSERT ? "assert" : "", event & PPS_CAPTURECLEAR ? "clear" : ""); } @@ -112,7 +112,7 @@ struct pps_device *pps_register_source(struct pps_sourc= e_info *info, goto kfree_pps; } =20 - dev_info(pps->dev, "new PPS source %s\n", info->name); + dev_info(&pps->dev, "new PPS source %s\n", info->name); =20 return pps; =20 @@ -166,7 +166,7 @@ void pps_event(struct pps_device *pps, struct pps_event= _time *ts, int event, /* check event type */ BUG_ON((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) =3D=3D 0); =20 - dev_dbg(pps->dev, "PPS event at %lld.%09ld\n", + dev_dbg(&pps->dev, "PPS event at %lld.%09ld\n", (s64)ts->ts_real.tv_sec, ts->ts_real.tv_nsec); =20 timespec_to_pps_ktime(&ts_real, ts->ts_real); @@ -188,7 +188,7 @@ void pps_event(struct pps_device *pps, struct pps_event= _time *ts, int event, /* Save the time stamp */ pps->assert_tu =3D ts_real; pps->assert_sequence++; - dev_dbg(pps->dev, "capture assert seq #%u\n", + dev_dbg(&pps->dev, "capture assert seq #%u\n", pps->assert_sequence); =20 captured =3D ~0; @@ -202,7 +202,7 @@ void pps_event(struct pps_device *pps, struct pps_event= _time *ts, int event, /* Save the time stamp */ pps->clear_tu =3D ts_real; pps->clear_sequence++; - dev_dbg(pps->dev, "capture clear seq #%u\n", + dev_dbg(&pps->dev, "capture clear seq #%u\n", pps->clear_sequence); =20 captured =3D ~0; diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index f90ee483d343..64a8b34aa4ce 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -62,7 +62,7 @@ static int pps_cdev_pps_fetch(struct pps_device *pps, str= uct pps_fdata *fdata) else { unsigned long ticks; =20 - dev_dbg(pps->dev, "timeout %lld.%09d\n", + dev_dbg(&pps->dev, "timeout %lld.%09d\n", (long long) fdata->timeout.sec, fdata->timeout.nsec); ticks =3D fdata->timeout.sec * HZ; @@ -80,7 +80,7 @@ static int pps_cdev_pps_fetch(struct pps_device *pps, str= uct pps_fdata *fdata) =20 /* Check for pending signals */ if (err =3D=3D -ERESTARTSYS) { - dev_dbg(pps->dev, "pending signal caught\n"); + dev_dbg(&pps->dev, "pending signal caught\n"); return -EINTR; } =20 @@ -98,7 +98,7 @@ static long pps_cdev_ioctl(struct file *file, =20 switch (cmd) { case PPS_GETPARAMS: - dev_dbg(pps->dev, "PPS_GETPARAMS\n"); + dev_dbg(&pps->dev, "PPS_GETPARAMS\n"); =20 spin_lock_irq(&pps->lock); =20 @@ -114,7 +114,7 @@ static long pps_cdev_ioctl(struct file *file, break; =20 case PPS_SETPARAMS: - dev_dbg(pps->dev, "PPS_SETPARAMS\n"); + dev_dbg(&pps->dev, "PPS_SETPARAMS\n"); =20 /* Check the capabilities */ if (!capable(CAP_SYS_TIME)) @@ -124,14 +124,14 @@ static long pps_cdev_ioctl(struct file *file, if (err) return -EFAULT; if (!(params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) { - dev_dbg(pps->dev, "capture mode unspecified (%x)\n", + dev_dbg(&pps->dev, "capture mode unspecified (%x)\n", params.mode); return -EINVAL; } =20 /* Check for supported capabilities */ if ((params.mode & ~pps->info.mode) !=3D 0) { - dev_dbg(pps->dev, "unsupported capabilities (%x)\n", + dev_dbg(&pps->dev, "unsupported capabilities (%x)\n", params.mode); return -EINVAL; } @@ -144,7 +144,7 @@ static long pps_cdev_ioctl(struct file *file, /* Restore the read only parameters */ if ((params.mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) =3D=3D 0) { /* section 3.3 of RFC 2783 interpreted */ - dev_dbg(pps->dev, "time format unspecified (%x)\n", + dev_dbg(&pps->dev, "time format unspecified (%x)\n", params.mode); pps->params.mode |=3D PPS_TSFMT_TSPEC; } @@ -165,7 +165,7 @@ static long pps_cdev_ioctl(struct file *file, break; =20 case PPS_GETCAP: - dev_dbg(pps->dev, "PPS_GETCAP\n"); + dev_dbg(&pps->dev, "PPS_GETCAP\n"); =20 err =3D put_user(pps->info.mode, iuarg); if (err) @@ -176,7 +176,7 @@ static long pps_cdev_ioctl(struct file *file, case PPS_FETCH: { struct pps_fdata fdata; =20 - dev_dbg(pps->dev, "PPS_FETCH\n"); + dev_dbg(&pps->dev, "PPS_FETCH\n"); =20 err =3D copy_from_user(&fdata, uarg, sizeof(struct pps_fdata)); if (err) @@ -206,7 +206,7 @@ static long pps_cdev_ioctl(struct file *file, case PPS_KC_BIND: { struct pps_bind_args bind_args; =20 - dev_dbg(pps->dev, "PPS_KC_BIND\n"); + dev_dbg(&pps->dev, "PPS_KC_BIND\n"); =20 /* Check the capabilities */ if (!capable(CAP_SYS_TIME)) @@ -218,7 +218,7 @@ static long pps_cdev_ioctl(struct file *file, =20 /* Check for supported capabilities */ if ((bind_args.edge & ~pps->info.mode) !=3D 0) { - dev_err(pps->dev, "unsupported capabilities (%x)\n", + dev_err(&pps->dev, "unsupported capabilities (%x)\n", bind_args.edge); return -EINVAL; } @@ -227,7 +227,7 @@ static long pps_cdev_ioctl(struct file *file, if (bind_args.tsformat !=3D PPS_TSFMT_TSPEC || (bind_args.edge & ~PPS_CAPTUREBOTH) !=3D 0 || bind_args.consumer !=3D PPS_KC_HARDPPS) { - dev_err(pps->dev, "invalid kernel consumer bind" + dev_err(&pps->dev, "invalid kernel consumer bind" " parameters (%x)\n", bind_args.edge); return -EINVAL; } @@ -259,7 +259,7 @@ static long pps_cdev_compat_ioctl(struct file *file, struct pps_fdata fdata; int err; =20 - dev_dbg(pps->dev, "PPS_FETCH\n"); + dev_dbg(&pps->dev, "PPS_FETCH\n"); =20 err =3D copy_from_user(&compat, uarg, sizeof(struct pps_fdata_compat)); if (err) @@ -319,14 +319,13 @@ static const struct file_operations pps_cdev_fops =3D= { =20 static void pps_device_destruct(struct device *dev) { - struct pps_device *pps =3D dev_get_drvdata(dev); + struct pps_device *pps =3D container_of(dev, struct pps_device, dev); =20 /* Now we can release the ID for re-use */ pr_debug("deallocating pps%d\n", pps->id); scoped_guard(mutex, &pps_idr_lock) idr_remove(&pps_idr, pps->id); =20 - kfree(dev); kfree(pps); } =20 @@ -353,26 +352,25 @@ int pps_register_cdev(struct pps_device *pps) =20 devt =3D MKDEV(MAJOR(pps_devt), pps->id); =20 + device_initialize(&pps->dev); + pps->dev.devt =3D devt; + pps->dev.class =3D pps_class; + pps->dev.parent =3D pps->info.dev; + err =3D dev_set_name(&pps->dev, "pps%d", pps->id); + if (err) + goto put_dev; cdev_init(&pps->cdev, &pps_cdev_fops); pps->cdev.owner =3D pps->info.owner; - + cdev_set_parent(&pps->cdev, &pps->dev.kobj); err =3D cdev_add(&pps->cdev, devt, 1); if (err) - goto free_idr; - - pps->dev =3D device_create(pps_class, pps->info.dev, devt, pps, - "pps%d", pps->id); - if (IS_ERR(pps->dev)) { - err =3D PTR_ERR(pps->dev); + goto put_dev; + err =3D device_add(&pps->dev); + if (err) goto del_cdev; - } - - cdev_set_parent(&pps->cdev, &pps->dev->kobj); - /* Compensate for setting the parent after cdev_add() */ - get_device(pps->dev); =20 /* Override the release function with our own */ - pps->dev->release =3D pps_device_destruct; + pps->dev.release =3D pps_device_destruct; =20 pr_debug("source %s got cdev (%d:%d)\n", pps->info.name, MAJOR(pps_devt), pps->id); @@ -381,8 +379,8 @@ int pps_register_cdev(struct pps_device *pps) =20 del_cdev: cdev_del(&pps->cdev); - -free_idr: +put_dev: + put_device(&pps->dev); scoped_guard(mutex, &pps_idr_lock) idr_remove(&pps_idr, pps->id); pr_err("%s: failed to add char device %d:%d\n", @@ -394,8 +392,9 @@ void pps_unregister_cdev(struct pps_device *pps) { pr_debug("unregistering pps%d\n", pps->id); pps->lookup_cookie =3D NULL; - device_destroy(pps_class, pps->dev->devt); + device_del(&pps->dev); cdev_del(&pps->cdev); + put_device(&pps->dev); } =20 /* diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h index 78c8ac4951b5..d1edacb7e63e 100644 --- a/include/linux/pps_kernel.h +++ b/include/linux/pps_kernel.h @@ -57,7 +57,7 @@ struct pps_device { unsigned int id; /* PPS source unique ID */ void const *lookup_cookie; /* For pps_lookup_dev() only */ struct cdev cdev; - struct device *dev; + struct device dev; struct fasync_struct *async_queue; /* fasync method */ spinlock_t lock; }; --=20 2.47.0