From nobody Sun Feb 8 01:32:58 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 E2E4019D88B for ; Mon, 2 Dec 2024 16:35:16 +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=1733157319; cv=none; b=WWx7RnnB/5kWbfrjzMlBWW8nPJ+sziog7c9mBQNdUziZwtywNkm+PHeVh5/y8oQW/Sd1vw3M6PGhALlhPr7si90T1UIuZ7iUxTuqL6cfQ27wbd2UD9j+qf6emxuBnq+yyQ1XRvPIzzQZx9gUIiehDa28iEAG4vyL01XSw6tcI4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157319; c=relaxed/simple; bh=2WJjzL+pv8PFUXma2u5w7rZ1vfalpOgBja+PmYhDx+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hvySXtDH5/VsarGXF6wSz/yLHduptJu8nr1ER12YQZpVshZsYg7FIOcWPG5pNOqsghUAXcPUhtdxW+jKM6JOJms1C43Y3tP2jWfjtS/TzJuv69LMXJvfrvJlbqMVclCoaNVkps8ikGZqul0XEixtqJ89tHM5F7Cv+DCziEpYyu8= 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=OmEWtfO0; 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="OmEWtfO0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733157315; 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=HyGIJzVjB5pGO8vz5bCSJn+OKkV4sWqeKPCojQqGMsI=; b=OmEWtfO0bg17fVGpDLux9kOBS6OwLkfBEP7fOVq/m0KPb/VHaa4wCFS+oafsq8ZdZvBgFR VngBbwSRvQzfLGrazxBOTb99UEyu7KbSC5gXunZr6tNJ+tDkWq+HPGxM9tGgo0M7Ycmn4g Ngrf9Ybe15CjntZVOCse6y1Q2fHUTzk= Received: from mx-prod-mc-05.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-617-mD4-SnjqMTOHeOCYYchrdw-1; Mon, 02 Dec 2024 11:35:13 -0500 X-MC-Unique: mD4-SnjqMTOHeOCYYchrdw-1 X-Mimecast-MFC-AGG-ID: mD4-SnjqMTOHeOCYYchrdw 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5D4901964CDF; Mon, 2 Dec 2024 16:35:10 +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 32FD0195608A; Mon, 2 Dec 2024 16:35:05 +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, stable@vger.kernel.org Subject: [PATCH 1/6] pps: fix cdev use-after-free Date: Mon, 2 Dec 2024 17:34:46 +0100 Message-ID: <20241202163451.1442566-2-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" The lifetime of a struct pps_device and the struct cdev embedded in it is under control of the associated struct device. The cdev's .open/.release methods (pps_cdev_{open,release}()) try to keep the device alive while the cdev is open, but this is insufficient. Consider this sequence: 1. Attach the PPS line discipline to a TTY. 2. Open the created /dev/pps* file. 3. Detach the PPS line discipline. 4. Close the file. In this scenario, the last reference to the cdev is not released from pps code, but in __fput(), *after* running the .release method, which frees the pps_device (including struct cdev). Fix this by using cdev_set_parent() to ensure that the pps_device outlives the cdev. cdev_set_parent() should be used before cdev_add(), but we can't do that here, because at that point we don't have the dev yet. It's created in the next step with device_create(). To compensate, bump the refcount of the dev, which is what cdev_add() would have done if we followed the usual order. This will be cleaned up in subsequent patches. With the parent relationship in place, the .open/.release methods no longer need to change the refcount. The cdev reference held by the core filesystem code is enough to keep the pps device alive. The .release method had nothing else to do, so remove it. Move the cdev_del() from pps_device_destruct() to pps_unregister_cdev(). This is necessary. Otherwise, the pps_device would be holding a reference to itself and never get released. It also brings symmetry between pps_register_cdev() and pps_unregister_cdev(). KASAN detection of the bug: pps_core: deallocating pps0 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BUG: KASAN: slab-use-after-free in cdev_put+0x4e/0x50 Read of size 8 at addr ff1100001c1c7360 by task sleep/1192 CPU: 0 UID: 0 PID: 1192 Comm: sleep Not tainted 6.12.0-0.rc7.59.fc42.x86_6= 4+debug #1 Hardware name: Red Hat OpenStack Compute, BIOS 1.14.0-1.module+el8.4.0+885= 5+a9e237a9 04/01/2014 Call Trace: dump_stack_lvl+0x84/0xd0 print_report+0x174/0x505 kasan_report+0xab/0x180 cdev_put+0x4e/0x50 __fput+0x725/0xaa0 task_work_run+0x119/0x200 do_exit+0x8ef/0x27a0 do_group_exit+0xbc/0x250 get_signal+0x1b78/0x1e00 arch_do_signal_or_restart+0x8f/0x570 syscall_exit_to_user_mode+0x1f4/0x290 do_syscall_64+0xa3/0x190 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f6c598342d6 Code: Unable to access opcode bytes at 0x7f6c598342ac. RSP: 002b:00007ffff3528160 EFLAGS: 00000202 ORIG_RAX: 00000000000000e6 RAX: fffffffffffffdfc RBX: 00007f6c597c5740 RCX: 00007f6c598342d6 RDX: 00007ffff35281f0 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 00007ffff3528170 R08: 0000000000000000 R09: 0000000000000000 R10: 00007ffff35281e0 R11: 0000000000000202 R12: 00007f6c597c56c8 R13: 00007ffff35281e0 R14: 000000000000003c R15: 00007ffff35281e0 Allocated by task 1186: kasan_save_stack+0x30/0x50 kasan_save_track+0x14/0x30 __kasan_kmalloc+0x8f/0xa0 pps_register_source+0xe4/0x360 pps_tty_open+0x191/0x220 [pps_ldisc] tty_ldisc_open+0x75/0xc0 tty_set_ldisc+0x29e/0x730 tty_ioctl+0x866/0x11e0 __x64_sys_ioctl+0x12e/0x1a0 do_syscall_64+0x97/0x190 entry_SYSCALL_64_after_hwframe+0x76/0x7e Freed by task 1192: kasan_save_stack+0x30/0x50 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x70 __kasan_slab_free+0x37/0x50 kfree+0x140/0x4d0 device_release+0x9c/0x210 kobject_put+0x17c/0x4b0 pps_cdev_release+0x56/0x70 __fput+0x368/0xaa0 task_work_run+0x119/0x200 do_exit+0x8ef/0x27a0 do_group_exit+0xbc/0x250 get_signal+0x1b78/0x1e00 arch_do_signal_or_restart+0x8f/0x570 syscall_exit_to_user_mode+0x1f4/0x290 do_syscall_64+0xa3/0x190 entry_SYSCALL_64_after_hwframe+0x76/0x7e The buggy address belongs to the object at ff1100001c1c7200 which belongs to the cache kmalloc-rnd-02-512 of size 512 The buggy address is located 352 bytes inside of freed 512-byte region [ff1100001c1c7200, ff1100001c1c7400) [...] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Fixes: eae9d2ba0cfc ("LinuxPPS: core support") Fixes: d953e0e837e6 ("pps: Fix a use-after free bug when unregistering a so= urce.") Cc: stable@vger.kernel.org Signed-off-by: Michal Schmidt --- drivers/pps/pps.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 25d47907db17..4f497353daa2 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -301,15 +301,6 @@ static int pps_cdev_open(struct inode *inode, struct f= ile *file) struct pps_device *pps =3D container_of(inode->i_cdev, struct pps_device, cdev); file->private_data =3D pps; - kobject_get(&pps->dev->kobj); - return 0; -} - -static int pps_cdev_release(struct inode *inode, struct file *file) -{ - struct pps_device *pps =3D container_of(inode->i_cdev, - struct pps_device, cdev); - kobject_put(&pps->dev->kobj); return 0; } =20 @@ -324,15 +315,12 @@ static const struct file_operations pps_cdev_fops =3D= { .compat_ioctl =3D pps_cdev_compat_ioctl, .unlocked_ioctl =3D pps_cdev_ioctl, .open =3D pps_cdev_open, - .release =3D pps_cdev_release, }; =20 static void pps_device_destruct(struct device *dev) { struct pps_device *pps =3D dev_get_drvdata(dev); =20 - cdev_del(&pps->cdev); - /* Now we can release the ID for re-use */ pr_debug("deallocating pps%d\n", pps->id); mutex_lock(&pps_idr_lock); @@ -383,6 +371,10 @@ int pps_register_cdev(struct pps_device *pps) goto del_cdev; } =20 + cdev_set_parent(&pps->cdev, &pps->dev->kobj); + /* Compensate for setting the parent after cdev_add() */ + get_device(pps->dev); + /* Override the release function with our own */ pps->dev->release =3D pps_device_destruct; =20 @@ -407,6 +399,7 @@ 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); + cdev_del(&pps->cdev); } =20 /* --=20 2.47.0 From nobody Sun Feb 8 01:32:58 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 CC8201AF4C1 for ; Mon, 2 Dec 2024 16:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157323; cv=none; b=Dzk2qnis7MwzRd+wfJ67vedk/EplYPz0XYv3/x6CA0RRx92lTutAGVvnJ7bCwild86qATFtBxD3wjW2928IoCYlAAU+IgTS5z8EVbLXx87ZfwNGNqp0h8X6n04PI5UeDRVuQ1Ri0/aWNsmbWy/fuSLD4LzVqyLrv66WPRzpAUN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157323; c=relaxed/simple; bh=PZFWMMZcLO/qhlPXqW6e0YrlQMvPOyvQ/klWUVWdxmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iXuptkTOGY9y83tzXiH9wQy655BR1eXWk8cTekr26zxrjDmC+m5bxg/1j6AsPAz0wKx9lxn+DT7zZ72BX94FBbVw7b7QG1KvSUmJZSInJIDpiCywxgKpjDYgBkpVj4pxa7sj1D84AAeTXRGLsiDG4Y8ObisE10b037IjIScGNz8= 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=ig0uKw4v; arc=none smtp.client-ip=170.10.133.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="ig0uKw4v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733157320; 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=5PSHFNlDA9lcePqjIa440ia9/4xR3F3nAudrFnACkrk=; b=ig0uKw4vTd8yVv+rovtJbFKoxqpnuvPbt2E6/v9oGMnT3Emt4cFAU1F4D/YU/ZQj7PrZXo etqtAl5gOQEvruckwaDEgIKBXtqRtaAFuPO0CS2PzbaPj7oQl0ysbB+1dDKE8j7AWFT7cB SC2wAXhBo4wz2oOjC7HZme/9sEr7REA= Received: from mx-prod-mc-05.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-134-CmKKg31rPTqwnMDqqfjwJg-1; Mon, 02 Dec 2024 11:35:17 -0500 X-MC-Unique: CmKKg31rPTqwnMDqqfjwJg-1 X-Mimecast-MFC-AGG-ID: CmKKg31rPTqwnMDqqfjwJg 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5700D1964CF4; Mon, 2 Dec 2024 16:35:15 +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 E668B195605F; Mon, 2 Dec 2024 16:35:10 +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 2/6] pps: simplify pps_idr_lock locking Date: Mon, 2 Dec 2024 17:34:47 +0100 Message-ID: <20241202163451.1442566-3-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" It is sufficient to hold pps_idr_lock only around the idr (de)allocations. There is no reason for the assignment to pps->id or for the error printing to be under the lock. Simplify the pps_idr_lock locking and the error path. Signed-off-by: Michal Schmidt --- drivers/pps/pps.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 4f497353daa2..9a631f6d3a1e 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -336,22 +336,22 @@ int pps_register_cdev(struct pps_device *pps) int err; dev_t devt; =20 - mutex_lock(&pps_idr_lock); /* * Get new ID for the new PPS source. After idr_alloc() calling * the new source will be freely available into the kernel. */ + mutex_lock(&pps_idr_lock); err =3D idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL); + mutex_unlock(&pps_idr_lock); if (err < 0) { if (err =3D=3D -ENOSPC) { pr_err("%s: too many PPS sources in the system\n", pps->info.name); err =3D -EBUSY; } - goto out_unlock; + return err; } pps->id =3D err; - mutex_unlock(&pps_idr_lock); =20 devt =3D MKDEV(MAJOR(pps_devt), pps->id); =20 @@ -389,7 +389,6 @@ int pps_register_cdev(struct pps_device *pps) free_idr: mutex_lock(&pps_idr_lock); idr_remove(&pps_idr, pps->id); -out_unlock: mutex_unlock(&pps_idr_lock); return err; } --=20 2.47.0 From nobody Sun Feb 8 01:32:58 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 DA7C31A263F for ; Mon, 2 Dec 2024 16:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157330; cv=none; b=cwpSWVNg3Smgu91m8NRg+WwpAMBQjF33WFh82Tu7vjYaBMYQtA3oZSZrnyEdJmyGejsBWnzEVmnhmhoDAsWm0/zAwYCsosFfcW5SUN1m8WocO4au0gS02J8/J2+UhBCkZ2Bj0MqsRJvz+vtIZa4TD5H+sLbXKihvTiLyVuoaLBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157330; c=relaxed/simple; bh=w+ZcGKebnCge9cWTm+RUJ97cLvqTCMo8kHxVVTYWbKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y3YCs9odJyCHBp6zLmBNRfY4kwmW146PT8ZCNNLKb36EPKXtAJ/6iY3ljB2RNbaToneVnbPe+ZcPd4XmssMq982/x19I/POPD7mdjC0wACARAG7aKEKqcoOLMm3oSsjhl7oQdXBWqTlJsXUVS7niZe8yoreWnqltQeSNkktvh3w= 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=HNrHjCaW; arc=none smtp.client-ip=170.10.133.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="HNrHjCaW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733157325; 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=Zjeefh/Ite+E0sy7DyA+HC2ndpLT7TPRyVlqY/4lKWs=; b=HNrHjCaW/HxOVL8M6eXbNHRWkF2WEaSDtSfc8eDMZ6gEH76s+8LhLY+aageeYh96/W0ac2 TDSL1DAAsfQZlMmdz/LIZyUNRappyjiM0dSzDmopbOYeYp9GTQ1BRg1QF6h1sc9ozxNV9o 7b57Bx/WXybx4X8CdfbDFRojcL7U57M= 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-652-OAHhXO0mN5egkWvU2y1x9Q-1; Mon, 02 Dec 2024 11:35:22 -0500 X-MC-Unique: OAHhXO0mN5egkWvU2y1x9Q-1 X-Mimecast-MFC-AGG-ID: OAHhXO0mN5egkWvU2y1x9Q 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 DFC281944D3E; Mon, 2 Dec 2024 16:35:19 +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 1C0FC1956089; Mon, 2 Dec 2024 16:35:15 +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 3/6] pps: use scoped_guard for pps_idr_lock Date: Mon, 2 Dec 2024 17:34:48 +0100 Message-ID: <20241202163451.1442566-4-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" Use the scoped_guard syntax to be more brief. Signed-off-by: Michal Schmidt --- drivers/pps/pps.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 9a631f6d3a1e..92be7815a621 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -323,9 +323,8 @@ static void pps_device_destruct(struct device *dev) =20 /* Now we can release the ID for re-use */ pr_debug("deallocating pps%d\n", pps->id); - mutex_lock(&pps_idr_lock); - idr_remove(&pps_idr, pps->id); - mutex_unlock(&pps_idr_lock); + scoped_guard(mutex, &pps_idr_lock) + idr_remove(&pps_idr, pps->id); =20 kfree(dev); kfree(pps); @@ -340,9 +339,8 @@ int pps_register_cdev(struct pps_device *pps) * Get new ID for the new PPS source. After idr_alloc() calling * the new source will be freely available into the kernel. */ - mutex_lock(&pps_idr_lock); - err =3D idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL); - mutex_unlock(&pps_idr_lock); + scoped_guard(mutex, &pps_idr_lock) + err =3D idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL); if (err < 0) { if (err =3D=3D -ENOSPC) { pr_err("%s: too many PPS sources in the system\n", @@ -387,9 +385,8 @@ int pps_register_cdev(struct pps_device *pps) cdev_del(&pps->cdev); =20 free_idr: - mutex_lock(&pps_idr_lock); - idr_remove(&pps_idr, pps->id); - mutex_unlock(&pps_idr_lock); + scoped_guard(mutex, &pps_idr_lock) + idr_remove(&pps_idr, pps->id); return err; } =20 --=20 2.47.0 From nobody Sun Feb 8 01:32:58 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 0F64F1A4F20 for ; Mon, 2 Dec 2024 16:35:30 +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=1733157332; cv=none; b=BenZUoarRo6CcnPt4Wv3zjX/opVZlPCzOjL2gHsGzcfDcejrdAB7/LxLOd+kErxGd2wO3L74Fr/uFnx/YOU5OJeUo9KbdH9N4cKOM2/zaCM5AqUUL8BBKfD88IXN8M4thPLKMHVtOIQx7Eoq3QDehcaMjyWJpH1Gwzxr6pAaE9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157332; c=relaxed/simple; bh=RUqSuOrIU5RfL1TOZs7Z5ENFkMnZ9Q1EPtuXOwalsAQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f6FEZoRV92M36T8MZFQ0ybVyhSuJVCh5gGYgAulcsXziLlGgFfRmNmm8MEowgHtelz34evhKtbMPO3qJGc+7zYee/e6p19+ifbIOQDW8hNpLm+tanETNoh3mugUOKdUCg1dLi9SPuzYyhmTVM2PZPG7rVwSjicQ+ppVnlDyeL+Y= 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=CiueJSIJ; 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="CiueJSIJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733157330; 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=ZpeDd+7B9ztAilsfvA8YQqfJL+Dpex3xILQfCZIzWdg=; b=CiueJSIJH/4Vrn29Bv8N6UCe+aj13hEWlqG8bT8o+wUue+ZHRqdL4LqlJII6aUIUFh1IIX Z9uGVWhzS1FP7O0TcpbMtCWYtLJNlriYlwC9vd8zF2Zeiu3zxHOrAMWrBOZ6Lw4kbuJ7gF 9mdXFfGoky0eYy/cN20IdCRRRL1r9As= Received: from mx-prod-mc-01.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-207-q8ccNZUINeWjn9YamZk7VA-1; Mon, 02 Dec 2024 11:35:26 -0500 X-MC-Unique: q8ccNZUINeWjn9YamZk7VA-1 X-Mimecast-MFC-AGG-ID: q8ccNZUINeWjn9YamZk7VA 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 836FB1955F40; Mon, 2 Dec 2024 16:35:24 +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 ABE2F195608A; Mon, 2 Dec 2024 16:35:20 +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 4/6] pps: print error in both cdev and dev error paths in pps_register_cdev() Date: Mon, 2 Dec 2024 17:34:49 +0100 Message-ID: <20241202163451.1442566-5-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" For pps, a device_create() failure is just as severe as a cdev_add() failure. Print the error message in both cases. Signed-off-by: Michal Schmidt --- drivers/pps/pps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 92be7815a621..f90ee483d343 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -357,11 +357,9 @@ int pps_register_cdev(struct pps_device *pps) pps->cdev.owner =3D pps->info.owner; =20 err =3D cdev_add(&pps->cdev, devt, 1); - if (err) { - pr_err("%s: failed to add char device %d:%d\n", - pps->info.name, MAJOR(pps_devt), pps->id); + 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)) { @@ -387,6 +385,8 @@ int pps_register_cdev(struct pps_device *pps) free_idr: scoped_guard(mutex, &pps_idr_lock) idr_remove(&pps_idr, pps->id); + pr_err("%s: failed to add char device %d:%d\n", + pps->info.name, MAJOR(pps_devt), pps->id); return err; } =20 --=20 2.47.0 From nobody Sun Feb 8 01:32:58 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 From nobody Sun Feb 8 01:32:58 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 255C01DA622 for ; Mon, 2 Dec 2024 16:35:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157345; cv=none; b=KKjNzPFyj7qB8EtHoS3hx7wiC1ZmQy8m+ZqZcWneqKSxuLwFm0gf8qKet3Sq5SQ2BqBzIUy/I7eHn+FLeEXMCOnEhv7sMqgOiSXk/ANmhe76JOUlxWyT9Hxl3gJPhvY2g1nWAACb0Jz9AGUPpSVEVtRptoH6X1YYnAveyZXZD+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733157345; c=relaxed/simple; bh=lu/T8c/ONtFclthiZfbjtk5Klo4nJJWTbw0vZYcIpiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JbQms+cq5ZavzqM04ZuKKmOYKdHjbP17OVVcKUfz2QzawTE57L3vlSkRYdiDiJBpSiMt2AmqIZuXVhAYxtMJ2bTfx//CFVowUGgn4sAFvQF1mdLMctzr4chPXYKvadGtIEpBGuT9+0CtG0X4msUPFObgyS8S0mHcZ01rPBMO+i4= 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=N32fYeE1; arc=none smtp.client-ip=170.10.133.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="N32fYeE1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733157342; 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=MD7vpVzmNdr2zkj6ePakrYVQbOesXQVj6yS9qMqPqYA=; b=N32fYeE1G+m5facH/k5Nu6Ky4lMiALJbXzk8QbVnjXX+JjzVF3r7Oo4BUZ/2P7iH6692wz aPQ/rsWfVyg8xHKA2IUitd2gJcK8e/fNKiLdSU34mxIvdoTlDb7FxAhSxE3lbd44KhqCj3 J8/JpZcKpxJKJ732lU43ObUZdgmfrtI= Received: from mx-prod-mc-01.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-632-kTsgXmKUOoSBAhS4dEswpQ-1; Mon, 02 Dec 2024 11:35:36 -0500 X-MC-Unique: kTsgXmKUOoSBAhS4dEswpQ-1 X-Mimecast-MFC-AGG-ID: kTsgXmKUOoSBAhS4dEswpQ 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5DAAD195FD0C; Mon, 2 Dec 2024 16:35:33 +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 CD0471956067; Mon, 2 Dec 2024 16:35:29 +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 6/6] pps: use cdev_device_add() Date: Mon, 2 Dec 2024 17:34:51 +0100 Message-ID: <20241202163451.1442566-7-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" The cdev_set_parent() + cdev_add() + device_add() sequence is just open-coded cdev_device_add(). Use it. Signed-off-by: Michal Schmidt --- drivers/pps/pps.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 64a8b34aa4ce..89b502855e7b 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -361,13 +361,10 @@ int pps_register_cdev(struct pps_device *pps) 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); + + err =3D cdev_device_add(&pps->cdev, &pps->dev); if (err) goto put_dev; - err =3D device_add(&pps->dev); - if (err) - goto del_cdev; =20 /* Override the release function with our own */ pps->dev.release =3D pps_device_destruct; @@ -377,8 +374,6 @@ int pps_register_cdev(struct pps_device *pps) =20 return 0; =20 -del_cdev: - cdev_del(&pps->cdev); put_dev: put_device(&pps->dev); scoped_guard(mutex, &pps_idr_lock) @@ -392,8 +387,7 @@ void pps_unregister_cdev(struct pps_device *pps) { pr_debug("unregistering pps%d\n", pps->id); pps->lookup_cookie =3D NULL; - device_del(&pps->dev); - cdev_del(&pps->cdev); + cdev_device_del(&pps->cdev, &pps->dev); put_device(&pps->dev); } =20 --=20 2.47.0