From nobody Wed Oct 8 20:01:06 2025 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 7B17E25E44B; Wed, 25 Jun 2025 11:52:42 +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=1750852364; cv=none; b=hUCjLWTAvfVi+gB8BFFXJwN4ZobUeXfdtNwyneNy3bUd8MHyKORyQGXBMSa46CxZEpXh46NaGzSqER4uFgTY5tKmks9oziBsXlGnPDm7vMdrIVXnnc9Z3j5zzOKKWwDCGtr2XVA7yIXBBJH0WFp0/g3b/8VIi7hpa/8YvAzFmso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750852364; c=relaxed/simple; bh=TWIqKKbfG6uuI5HtJ3eC8YlrZRXG3e3FNtS1Y27gBWY=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=G8cem57f2PKYvdARL9aNc/1Y5yTt9oeT1l9MRQaNWaQYzJx9uBSvzk7jKwe4zDdZm+Jwh7bOf1+HlS04VWV0bus8u5wQ9Ok2YHY/UvDNEkNEcO0z9OQNntxH8OuCStw459iW8UDanP+Vs9acKXdUk8QD9mHYTWz5tS/sMWlFrPY= 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=ij1geo9+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yI77TiUa; 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="ij1geo9+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yI77TiUa" Message-ID: <20250625115133.486953538@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750852359; 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: references:references; bh=GCssfyGvJulb+kWMiAtrGha00DmPusbjNgsxf3WrhOI=; b=ij1geo9+GrIYRBF5s3mgwgO/FAfNNTqkmPB8Xy5nTJi1av60V6YnQdQ6PoSpdiVKpX0cQN UFE4AYhgYiPogILMxtFY2aWsEYwB70GsbFeyro8Yxx04hLV5yb5IwKErr7lInhabF5YyEr zryubZbPNYe1nROE2hXmeenMBmS7VcZrNnLg3PI2HjydFj5UAlfj28qCgKb31fMK01QX+I TIjlom64jjT3Wt5I4aJPsq50gfyUYNo4SqzxMiScG0Y1c15uG3u/szXD3l6P6A+0X7DGy2 uYN5tJJ6dSJvDOKShekQCbt4dLMoTx8+VHCJHnpzVqTpoVLMuD1DdWOa2qRnSw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750852359; 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: references:references; bh=GCssfyGvJulb+kWMiAtrGha00DmPusbjNgsxf3WrhOI=; b=yI77TiUaBFd0b2giLZAR3Rs2r4RQHtySXnAtTI/QfaEbAzV+CzTK+nPIsGtM/eejba2I45 v6UtiPDj/3WmR2AQ== From: Thomas Gleixner To: LKML Cc: Richard Cochran , netdev@vger.kernel.org, Vadim Fedorenko , Paolo Abeni , Jakub Kicinski Subject: [patch V2 13/13] ptp: Simplify ptp_read() References: <20250625114404.102196103@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 25 Jun 2025 13:52:39 +0200 (CEST) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The mixture of gotos and direct return codes is inconsistent and just makes the code harder to read. Let it consistently return error codes directly and tidy the code flow up accordingly. No functional change intended. Signed-off-by: Thomas Gleixner --- V2: Fix the return value - Paolo Drop the __free() part - Jakub --- drivers/ptp/ptp_chardev.c | 54 +++++++++++++----------------------------= ----- 1 file changed, 16 insertions(+), 38 deletions(-) --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -106,8 +106,7 @@ int ptp_set_pinfunc(struct ptp_clock *pt =20 int ptp_open(struct posix_clock_context *pccontext, fmode_t fmode) { - struct ptp_clock *ptp =3D - container_of(pccontext->clk, struct ptp_clock, clock); + struct ptp_clock *ptp =3D container_of(pccontext->clk, struct ptp_clock, = clock); struct timestamp_event_queue *queue; char debugfsname[32]; =20 @@ -536,67 +535,46 @@ long ptp_ioctl(struct posix_clock_contex ssize_t ptp_read(struct posix_clock_context *pccontext, uint rdflags, char __user *buf, size_t cnt) { - struct ptp_clock *ptp =3D - container_of(pccontext->clk, struct ptp_clock, clock); + struct ptp_clock *ptp =3D container_of(pccontext->clk, struct ptp_clock, = clock); struct timestamp_event_queue *queue; struct ptp_extts_event *event; - int result; + ssize_t result; =20 queue =3D pccontext->private_clkdata; - if (!queue) { - result =3D -EINVAL; - goto exit; - } + if (!queue) + return -EINVAL; =20 - if (cnt % sizeof(struct ptp_extts_event) !=3D 0) { - result =3D -EINVAL; - goto exit; - } + if (cnt % sizeof(*event) !=3D 0) + return -EINVAL; =20 if (cnt > EXTTS_BUFSIZE) cnt =3D EXTTS_BUFSIZE; =20 - cnt =3D cnt / sizeof(struct ptp_extts_event); - - if (wait_event_interruptible(ptp->tsev_wq, - ptp->defunct || queue_cnt(queue))) { + if (wait_event_interruptible(ptp->tsev_wq, ptp->defunct || queue_cnt(queu= e))) return -ERESTARTSYS; - } =20 - if (ptp->defunct) { - result =3D -ENODEV; - goto exit; - } + if (ptp->defunct) + return -ENODEV; =20 event =3D kmalloc(EXTTS_BUFSIZE, GFP_KERNEL); - if (!event) { - result =3D -ENOMEM; - goto exit; - } + if (!event) + return -ENOMEM; =20 scoped_guard(spinlock_irq, &queue->lock) { - size_t qcnt =3D queue_cnt(queue); - - if (cnt > qcnt) - cnt =3D qcnt; + size_t qcnt =3D min((size_t)queue_cnt(queue), cnt / sizeof(*event)); =20 - for (size_t i =3D 0; i < cnt; i++) { + for (size_t i =3D 0; i < qcnt; i++) { event[i] =3D queue->buf[queue->head]; /* Paired with READ_ONCE() in queue_cnt() */ WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS); } + cnt =3D qcnt * sizeof(*event); } =20 - cnt =3D cnt * sizeof(struct ptp_extts_event); - result =3D cnt; - if (copy_to_user(buf, event, cnt)) { + if (copy_to_user(buf, event, cnt)) result =3D -EFAULT; - goto free_event; - } =20 -free_event: kfree(event); -exit: return result; }