From patchwork Fri Feb 7 09:39:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13964687 X-Patchwork-Delegate: kuba@kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 E6E6D13C9A3; Fri, 7 Feb 2025 09:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921151; cv=none; b=if1Pvc3DoWge9/QZvvAXGin6+vdkeWrhIbjAnVVFUfSyscm/w9nEN+UBefO7FiX0mDFo5wZA1SAk6WRH7lJhdTk88xGjBCHbqgDxJIiZcOZGXE8Am+9KGgr6ucMW767djdbapDK4DIhwPrl/HutKOK5crSbMeJtqU8+zubtc8hw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921151; c=relaxed/simple; bh=kTfv69N70jRYPW4PfE2gGidB3Lx+7n93IMhTANRVrYE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ravht3/O4MK8W3rYS7o3TPWa54uOyKxDGocO6HCBaeXeMoPwBehrqF8dpskalqgkvWg9PcHsyIF/zkn3bj+W8gOJWAN1rteRdjzYFWktreAI3rCv9/gHiS2AbaHZAtyxi4XBtah9oTC78f4mu/kV55qlu+Qo77wFJiovdSysDAo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pUPLgXFa; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rZNrnwW+; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pUPLgXFa"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rZNrnwW+" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1738921148; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OGKJRgcHeTsvHCCIhahevFs9ZoQcn4ms3fb+kPTrYUw=; b=pUPLgXFaDGWrQ5TSaSsCKK7CMqDdW27b68OIDaQM1CHubYZldfxMSWOp4pGzduuyh36qs1 T8yQSDklKXkuFklPN2EEBmEB7plqmpXoe8urrj+TmQzz7Mx6mTOjNX+in+ohHpStH/tmcC c6JR0q7KMY6RBe/01+TDHty2typlgcm6mPV9yFVP1bN3lObWNKbA8acLgcrWP/2n4RH9Ub ZLswa/zgY2yBTJEJIBiLj9ezhNwEwfUAaCzM2iLx+hAO25XNCIwX1A9B7h8rkRrWiQWocL 2g7jL5e5vX6uFSk1eZ/t0kCEZgabGqVZ+il9/+/tSyggg21RTHJ5exBhseGBaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1738921148; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OGKJRgcHeTsvHCCIhahevFs9ZoQcn4ms3fb+kPTrYUw=; b=rZNrnwW+9h7sQmNnvHKyUxWAMHxultlcKQzohTuYuJDqnHkbz+FuwsxPdgmIUGDPS5bviL CakQJH32PygzfCCg== Date: Fri, 07 Feb 2025 10:39:02 +0100 Subject: [PATCH net v2 1/5] ptp: vmclock: Add .owner to vmclock_miscdev_fops Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-vmclock-probe-v2-1-bc2fce0bdf07@linutronix.de> References: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> In-Reply-To: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> To: David Woodhouse , Richard Cochran , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Mateusz Polchlopek , David Woodhouse , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , stable@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1738921146; l=908; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=MFy8Kvx9GfNv7kEwQZwKavMJ1HFnaFSDW05FWmtv9l0=; b=FhK5DAQshdTsQDR3kmHqezcN25DxsO+GNEzCCmLMZaUkHHdxVobJAN70DHC3pWCzlbjKqnIYm rkbpqgaaKLsCgdQPRhJlJs6BUtoxDxWr/RogxLH4J+VVVUUhRmwVAOn X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Patchwork-Delegate: kuba@kernel.org From: David Woodhouse Without the .owner field, the module can be unloaded while /dev/vmclock0 is open, leading to an oops. Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device") Cc: stable@vger.kernel.org Signed-off-by: David Woodhouse Signed-off-by: Thomas Weißschuh --- drivers/ptp/ptp_vmclock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c index 0a2cfc8ad3c5408a87fd8fedeff274ab895de3dd..dbc73e5382935dcbc799ea608b87f5ff51044ebc 100644 --- a/drivers/ptp/ptp_vmclock.c +++ b/drivers/ptp/ptp_vmclock.c @@ -414,6 +414,7 @@ static ssize_t vmclock_miscdev_read(struct file *fp, char __user *buf, } static const struct file_operations vmclock_miscdev_fops = { + .owner = THIS_MODULE, .mmap = vmclock_miscdev_mmap, .read = vmclock_miscdev_read, }; From patchwork Fri Feb 7 09:39:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13964688 X-Patchwork-Delegate: kuba@kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 92E541A2381; Fri, 7 Feb 2025 09:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921152; cv=none; b=DgKtEviUfHrraspsHftOXjuJFziOHWocDeV2gRUfooDF/I5GNpDkuYFcah8YXLKUSPG9gatMfE6DElAFxTYAj1XvqYg11rldqRTpi/jQBSqX9jM/28NtR63R5MzII2ERr/9b8BWOWlDhbFC6Gg6EXh2YV2RKETKx+OSemTrp0gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921152; c=relaxed/simple; bh=1B5zPKA0Mc/6w7ghytEcBT/SVnSrsKvi3bjfjnQS5dQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sXZPVf4d4euV/CpfbAXm2HQfR0KdSoUWfg5al0vIbl6MN3janyx+azLOhgYsPMtMkDIyQvqCeLbjPcC8g/rPOdzl/2Rw2MRMU5MYz69sjrE6K+mh5tCwtt1TQjY943KYZnRLpSYvLoSfj85y7DNLLRHakpIxsz4wkVoOfQANk+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rWAawmeY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nRJNL+V1; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rWAawmeY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nRJNL+V1" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1738921148; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gupiaH3aeSrW49PewDfwsAeSLNT5/3bH/9opEvPC+nE=; b=rWAawmeYpAKH2GrmUVF1eNWG6Dzm0PfBotXhKAMp2wDyD1j4uhfpCVW8eJX5sFds5ic+CS 3/0Ie2Kru9i++SV1mS9PnjZFH2WbUSsN99CDsGWa7NBal4JtFbKx/oxEyUyC1tusNNz8zr OgGx36p7hJpX+azcnonw7ulJLhcMN7cCoRkvtGX0EtdIivuEVHUFBBeJdxH6JlXVKujAKp wMA4rlHigPTjtCOtLCbJVrlpsZiOYEB5zdF3DEMtmJyYYEM2tH1099D1SvwtGcmqfhkTpn JK/MnkOBwL7vffrX+5WOaYhab3BU8g+a1lutS6LpfR8409XffphwZJI6TVG1vA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1738921148; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gupiaH3aeSrW49PewDfwsAeSLNT5/3bH/9opEvPC+nE=; b=nRJNL+V1sL7A9lxTfPDnFb7Cg222V7wjuQaadfMYP4JO2Onxackby70dOFHvKAgzUXs8PI SLYLkdA7HShylfDA== Date: Fri, 07 Feb 2025 10:39:03 +0100 Subject: [PATCH net v2 2/5] ptp: vmclock: Set driver data before its usage Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-vmclock-probe-v2-2-bc2fce0bdf07@linutronix.de> References: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> In-Reply-To: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> To: David Woodhouse , Richard Cochran , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Mateusz Polchlopek , David Woodhouse , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , stable@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1738921146; l=1468; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=1B5zPKA0Mc/6w7ghytEcBT/SVnSrsKvi3bjfjnQS5dQ=; b=yc+Pliwu5No1r2SGJ9lf6wqlhDPZ0HotxZCwpfeSPNjpANxmq6CwDZdRimKDbNwI690DDS7Wg T2iK1l2zdw9DpirBjY1XwENdu86BlncH09V1jkKH9JN3VdQhCo8zIeb X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Patchwork-Delegate: kuba@kernel.org If vmclock_ptp_register() fails during probing, vmclock_remove() is called to clean up the ptp clock and misc device. It uses dev_get_drvdata() to access the vmclock state. However the driver data is not yet set at this point. Assign the driver data earlier. Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh Reviewed-by: Mateusz Polchlopek Acked-by: Richard Cochran Reviewed-by: David Woodhouse --- drivers/ptp/ptp_vmclock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c index dbc73e5382935dcbc799ea608b87f5ff51044ebc..1ba30a2da570fb4d1ec9db72820bf1781dfa9655 100644 --- a/drivers/ptp/ptp_vmclock.c +++ b/drivers/ptp/ptp_vmclock.c @@ -525,6 +525,8 @@ static int vmclock_probe(struct platform_device *pdev) goto out; } + dev_set_drvdata(dev, st); + if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC || le32_to_cpu(st->clk->size) > resource_size(&st->res) || le16_to_cpu(st->clk->version) != 1) { @@ -588,8 +590,6 @@ static int vmclock_probe(struct platform_device *pdev) (st->miscdev.minor && st->ptp_clock) ? ", " : "", st->ptp_clock ? "PTP" : ""); - dev_set_drvdata(dev, st); - out: return ret; } From patchwork Fri Feb 7 09:39:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13964689 X-Patchwork-Delegate: kuba@kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 D2F7E1DDA2F; Fri, 7 Feb 2025 09:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921152; cv=none; b=T7eS36m8rPg0XaQtNVpt6hEUeQJUgTZw+DN5BBmMu4YlBr2IHJWvvL1XvpTenrVKv7rACVI4XEn9U06D+h9EhMzc31kvKezqQzqBjwqIJxzIISKPT5f6wpLCXdwvl1bG3ivojbl382UOFdlu5hVc3EU/OpcmxeK+h/497vHzszg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921152; c=relaxed/simple; bh=67Qj7Rsb7HIT+rC3c3Khs/YT3YZlzU7gpEnE+MBUEP4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gQlJlnwnnW6EhyINgN/GY1keKDWErF2ujs6tRAFxN3/zKezsguj1nJ+OMHx/SEvGmPSMw62Hh9hCzfvc79LZ+gvrLTZXS5Vza1/0mklKnte1j+QYayzT7fSIIrLbGWbiG7sMzrJrBVn91gLKUe+V9hkXuvV7Q05ksIsOmgzIrN8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=h8YLWiD2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2WQ6m6nk; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="h8YLWiD2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2WQ6m6nk" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1738921149; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S9Y7amg6joot0ql0Loij+UqAMaqkQi9rCV9IvPg7dSo=; b=h8YLWiD2nzQMDRS60SYGfl8bWoZIHD8bFoJP266cu9y78xJxLYaRkFTmSycOD5rwhl3+Ub lZNfK0mbBDGI1kzEnEzM7tRqzTJ5h65UEZLxHHpgrH7JJ9qkO0zWNt8N6s+qIA0rNdTJZW xBr8uo/fGm+/vfMRxxa11WehcRqiGrljNanC4XcndqqSWgC8/I9s8UINpdRsqvm0TtY/L4 eCII8BZ+R/ZbPEOeMam28QssEJiC6t4M+H42QKt9WOnmrnWNO9mSR3u8Y/Ak2CNin3zIGm NKaCrNvK5fo6v4afyX1i6h5ic9l3gDzF88BOyuwsSFbEALOtO/ACb6r6rd1yJg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1738921149; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S9Y7amg6joot0ql0Loij+UqAMaqkQi9rCV9IvPg7dSo=; b=2WQ6m6nkrF368bMFQ18vNImSHuDcqKV1eqeJTACQTJwaGSqhlto6EveHe07Ecxvvi3/6/u 34ASIWgdR37gpbBg== Date: Fri, 07 Feb 2025 10:39:04 +0100 Subject: [PATCH net v2 3/5] ptp: vmclock: Don't unregister misc device if it was not registered Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-vmclock-probe-v2-3-bc2fce0bdf07@linutronix.de> References: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> In-Reply-To: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> To: David Woodhouse , Richard Cochran , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Mateusz Polchlopek , David Woodhouse , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , stable@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1738921146; l=1501; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=67Qj7Rsb7HIT+rC3c3Khs/YT3YZlzU7gpEnE+MBUEP4=; b=3xaMTeiqFBY8oD2NO24lNtTWbQDHgoSqqQPBGwKQWQ4M5MDOnn3H5ODx+lOMPSoNoAjN29mEp lp7g5molxWiC/jd1g89uFg2kuyf0tkgLU8RV1gWbOwo70zphHTeAScA X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Patchwork-Delegate: kuba@kernel.org vmclock_remove() tries to detect the successful registration of the misc device based on the value of its minor value. However that check is incorrect if the misc device registration was not attempted in the first place. Always initialize the minor number, so the check works properly. Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh Acked-by: Richard Cochran Reviewed-by: David Woodhouse --- drivers/ptp/ptp_vmclock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c index 1ba30a2da570fb4d1ec9db72820bf1781dfa9655..9b8bd626a397313433908fcc838edf8ffc3ecc98 100644 --- a/drivers/ptp/ptp_vmclock.c +++ b/drivers/ptp/ptp_vmclock.c @@ -550,6 +550,8 @@ static int vmclock_probe(struct platform_device *pdev) goto out; } + st->miscdev.minor = MISC_DYNAMIC_MINOR; + /* * If the structure is big enough, it can be mapped to userspace. * Theoretically a guest OS even using larger pages could still @@ -557,7 +559,6 @@ static int vmclock_probe(struct platform_device *pdev) * cross that bridge if/when we come to it. */ if (le32_to_cpu(st->clk->size) >= PAGE_SIZE) { - st->miscdev.minor = MISC_DYNAMIC_MINOR; st->miscdev.fops = &vmclock_miscdev_fops; st->miscdev.name = st->name; From patchwork Fri Feb 7 09:39:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13964690 X-Patchwork-Delegate: kuba@kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 601811DE2CB; Fri, 7 Feb 2025 09:39:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921153; cv=none; b=MBKrWEWSwH9FMKOkzijtrSmtqPV/RcWBbr5B48hF3NL0hrTi8v1L2158JHMhTA4lxevBIm8mqm55obncBeeCfhZ6ngyAAknmV4c3hu5S6efQxytuAI3J4sw9w4E/GET56EJ94qupNuVzGhAkgnjpAyiNjsu2BC+t/VE5flkvDN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921153; c=relaxed/simple; bh=9BdvaiGN4CMxY+MnMBf0Cl2uZSErRtKmf5nqWW9+l0M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=upR9Ik2IggF0M5OfcLRVDRTNl+uTkWIyRMHtJusMvGrp/m/k/VzbGaFSPCRrEVLoCeGgA30i8sEZMVOvSihSrBedb0cgEikHaDvS+gpVolJclRg+XW6tXOd48TuAbrVX0wpIxV3TcB21nhvHBd++1sHgCe4A7LxZ3MldtfHelVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kNoc2Jm9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=AkBuFU6r; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kNoc2Jm9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AkBuFU6r" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1738921149; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xGJfNVDGEZeCvHFsDxfQUXeGfHj0drDjlIthEqDcl+I=; b=kNoc2Jm9E1gADtuhLA8J3ck2ovBnXt8U3uV5u1VVu29K0gSSip+2wKbzlAgJEoer49xfXR viqtk6Smc28HqYTpj+mpho5a664Y9GnqA55B27SO8gSyhmXyGt/WGLgeKpQQdMg+k6VCUz 0+9XBLksnIkWQYYlrRyoO6zIRegwN1aFy2LbTkuakJmpx3qH0B8eUtMc2C4YIsvDJTeNhK SXwa7bWpiPDUrNEToSahzeJnLXgYOakKMp09ZRy4jl6/V6G8anaqCijKT9leeYnuHzwl8B vfwlvFE+baKj4e9WoJNmE7SUUfYUGVBzSr0KZ1+sYWZxyd6fIT+TrbMf3aWu+A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1738921149; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xGJfNVDGEZeCvHFsDxfQUXeGfHj0drDjlIthEqDcl+I=; b=AkBuFU6ruUA5HN4AW0OW/YeuVRTW67HBKSoA7zN5ksdVMYzyzEOwijBHgJgVk4SAk5WdsZ ta++eFdfDdhWoADQ== Date: Fri, 07 Feb 2025 10:39:05 +0100 Subject: [PATCH net v2 4/5] ptp: vmclock: Clean up miscdev and ptp clock through devres Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-vmclock-probe-v2-4-bc2fce0bdf07@linutronix.de> References: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> In-Reply-To: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> To: David Woodhouse , Richard Cochran , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Mateusz Polchlopek , David Woodhouse , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1738921146; l=2344; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=9BdvaiGN4CMxY+MnMBf0Cl2uZSErRtKmf5nqWW9+l0M=; b=0Hzf+ZarC+DPPnvuDCnyzYST6bYn3wVRliTirntTqz8xenrI2gJu+ypKLUItwUQM4oMdJpg1H HgYDZlA9jdHDj4I7YHpITEMkzhutNhk4u8M2V15elQQLfzXkvmf2a22 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Patchwork-Delegate: kuba@kernel.org Most resources owned by the vmclock device are managed through devres. Only the miscdev and ptp clock are managed manually. This makes the code slightly harder to understand than necessary. Switch them over to devres and remove the now unnecessary drvdata. Signed-off-by: Thomas Weißschuh Acked-by: Richard Cochran Reviewed-by: David Woodhouse --- drivers/ptp/ptp_vmclock.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c index 9b8bd626a397313433908fcc838edf8ffc3ecc98..09c023fb94b7e97137433bf18c3a065e26a36c6c 100644 --- a/drivers/ptp/ptp_vmclock.c +++ b/drivers/ptp/ptp_vmclock.c @@ -421,10 +421,9 @@ static const struct file_operations vmclock_miscdev_fops = { /* module operations */ -static void vmclock_remove(struct platform_device *pdev) +static void vmclock_remove(void *data) { - struct device *dev = &pdev->dev; - struct vmclock_state *st = dev_get_drvdata(dev); + struct vmclock_state *st = data; if (st->ptp_clock) ptp_clock_unregister(st->ptp_clock); @@ -525,8 +524,6 @@ static int vmclock_probe(struct platform_device *pdev) goto out; } - dev_set_drvdata(dev, st); - if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC || le32_to_cpu(st->clk->size) > resource_size(&st->res) || le16_to_cpu(st->clk->version) != 1) { @@ -552,6 +549,10 @@ static int vmclock_probe(struct platform_device *pdev) st->miscdev.minor = MISC_DYNAMIC_MINOR; + ret = devm_add_action_or_reset(&pdev->dev, vmclock_remove, st); + if (ret) + goto out; + /* * If the structure is big enough, it can be mapped to userspace. * Theoretically a guest OS even using larger pages could still @@ -574,7 +575,6 @@ static int vmclock_probe(struct platform_device *pdev) if (IS_ERR(st->ptp_clock)) { ret = PTR_ERR(st->ptp_clock); st->ptp_clock = NULL; - vmclock_remove(pdev); goto out; } } @@ -603,7 +603,6 @@ MODULE_DEVICE_TABLE(acpi, vmclock_acpi_ids); static struct platform_driver vmclock_platform_driver = { .probe = vmclock_probe, - .remove = vmclock_remove, .driver = { .name = "vmclock", .acpi_match_table = vmclock_acpi_ids, From patchwork Fri Feb 7 09:39:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13964691 X-Patchwork-Delegate: kuba@kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 D990A235BE6; Fri, 7 Feb 2025 09:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921154; cv=none; b=azPwYr7+slFVFhaE6GetLTql6X6K+V6kO1XiIFDsYmROaGY6mHYnD//lA85TCO4vkCu194J10wkMp32YcU+3QWENc8+ADqNA5ZaGJTQzaXfMHckF2IlBKxK9Gz+VJESAeV/3f/Im+Xtct/yHKbgeAlSlXIRN2RK9afDRS0Fh3OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921154; c=relaxed/simple; bh=PJ6dyjO0wMBUzryRHvH4B41hJgFPEjxdpjXQ/XTqvWU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fd7lrtbopy5qkNBRo5pckE5+PYa5Y8DmH1/5cnqZM9vlKHVCGlWJe3X0GNqA6zbrGnGqTNRA0G23smOoFCaIAxKLs/cRdPvTaF1J/ZisHWXSWtXnDgyuJXIKm+iRfwowDFSflEAloqfidwDgli5TfN4aCE6U9tZJPP697zZ0Qho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fx4WmK07; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=a3Yl0EH7; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fx4WmK07"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="a3Yl0EH7" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1738921150; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hhjHAzmbkaYnqcm3IHFcgDwG15AFP/Njjh4ZX0H9Olg=; b=fx4WmK074PHazK/ChkQrvakNhx//tQce39oX2maPhu55UejGiuWX1nm6XqjxEb399pDo0a TBAmqJjIA9gQ2xu1djoO7RlbYwJrh6O27lmZd6F0cKepCc0WFFYR74569Cb2dVerA673xD n29SZE6SWNDsaT+68+s6ZmljxyaL8WAfo+fKaQZ7rkUZIkwf1ibjmku23OeAiK/SEYoaSh 12aA5d2iIwDxT4vgDYbzz7rP+DAP8ECDy63pXK2G8kDfJIktUse36edyRKTf72VZbLhVYe vqNL/gDGS56oBAGtADrH2oxkF2dvFLAKBGhYwSv6ZoizfKIVvMunU0ct9TZgHQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1738921150; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hhjHAzmbkaYnqcm3IHFcgDwG15AFP/Njjh4ZX0H9Olg=; b=a3Yl0EH7a5YtE5adkLh/9jkArp+3DOYNpwtKcQe6zk5Vml0Q8MLB/GkEY8qNa878zKkZeZ 6YqitbjFwKcGfGAw== Date: Fri, 07 Feb 2025 10:39:06 +0100 Subject: [PATCH net v2 5/5] ptp: vmclock: Remove goto-based cleanup logic Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-vmclock-probe-v2-5-bc2fce0bdf07@linutronix.de> References: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> In-Reply-To: <20250207-vmclock-probe-v2-0-bc2fce0bdf07@linutronix.de> To: David Woodhouse , Richard Cochran , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Mateusz Polchlopek , David Woodhouse , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1738921146; l=3501; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=PJ6dyjO0wMBUzryRHvH4B41hJgFPEjxdpjXQ/XTqvWU=; b=4xFo8mAbUISvcDSNEowlGCBY90Hka4uuu5U+RKQz9mrzm14PjAuKipplOwuXOvw5YSvTpARM1 06uxENtxhvSDQzPzvMvvS07b0ufzJZxa8DSuzU40ym3K0kYPCB95/AW X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Patchwork-Delegate: kuba@kernel.org vmclock_probe() uses an "out:" label to return from the function on error. This indicates that some cleanup operation is necessary. However the label does not do anything as all resources are managed through devres, making the code slightly harder to read. Remove the label and just return directly. Signed-off-by: Thomas Weißschuh Acked-by: Richard Cochran Reviewed-by: David Woodhouse --- drivers/ptp/ptp_vmclock.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c index 09c023fb94b7e97137433bf18c3a065e26a36c6c..b3a83b03d9c14e10213c6cb94e6a42b38c59546f 100644 --- a/drivers/ptp/ptp_vmclock.c +++ b/drivers/ptp/ptp_vmclock.c @@ -506,14 +506,13 @@ static int vmclock_probe(struct platform_device *pdev) if (ret) { dev_info(dev, "Failed to obtain physical address: %d\n", ret); - goto out; + return ret; } if (resource_size(&st->res) < VMCLOCK_MIN_SIZE) { dev_info(dev, "Region too small (0x%llx)\n", resource_size(&st->res)); - ret = -EINVAL; - goto out; + return -EINVAL; } st->clk = devm_memremap(dev, st->res.start, resource_size(&st->res), MEMREMAP_WB | MEMREMAP_DEC); @@ -521,37 +520,34 @@ static int vmclock_probe(struct platform_device *pdev) ret = PTR_ERR(st->clk); dev_info(dev, "failed to map shared memory\n"); st->clk = NULL; - goto out; + return ret; } if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC || le32_to_cpu(st->clk->size) > resource_size(&st->res) || le16_to_cpu(st->clk->version) != 1) { dev_info(dev, "vmclock magic fields invalid\n"); - ret = -EINVAL; - goto out; + return -EINVAL; } ret = ida_alloc(&vmclock_ida, GFP_KERNEL); if (ret < 0) - goto out; + return ret; st->index = ret; ret = devm_add_action_or_reset(&pdev->dev, vmclock_put_idx, st); if (ret) - goto out; + return ret; st->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "vmclock%d", st->index); - if (!st->name) { - ret = -ENOMEM; - goto out; - } + if (!st->name) + return -ENOMEM; st->miscdev.minor = MISC_DYNAMIC_MINOR; ret = devm_add_action_or_reset(&pdev->dev, vmclock_remove, st); if (ret) - goto out; + return ret; /* * If the structure is big enough, it can be mapped to userspace. @@ -565,7 +561,7 @@ static int vmclock_probe(struct platform_device *pdev) ret = misc_register(&st->miscdev); if (ret) - goto out; + return ret; } /* If there is valid clock information, register a PTP clock */ @@ -575,15 +571,14 @@ static int vmclock_probe(struct platform_device *pdev) if (IS_ERR(st->ptp_clock)) { ret = PTR_ERR(st->ptp_clock); st->ptp_clock = NULL; - goto out; + return ret; } } if (!st->miscdev.minor && !st->ptp_clock) { /* Neither miscdev nor PTP registered */ dev_info(dev, "vmclock: Neither miscdev nor PTP available; not registering\n"); - ret = -ENODEV; - goto out; + return -ENODEV; } dev_info(dev, "%s: registered %s%s%s\n", st->name, @@ -591,8 +586,7 @@ static int vmclock_probe(struct platform_device *pdev) (st->miscdev.minor && st->ptp_clock) ? ", " : "", st->ptp_clock ? "PTP" : ""); - out: - return ret; + return 0; } static const struct acpi_device_id vmclock_acpi_ids[] = {