From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 881453CF02C for ; Tue, 16 Jun 2026 05:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781586770; cv=none; b=pydt+ycU1BZZu3fPdiq+jgzTVwMOg6EuxvHRZzBSoA573KAObHau3YTlXrtF3TpNIvrRr2XWpNsz4jA5Qhj4cnYw5Drwq08MaQcp56rZol4P2KhoZ9ne4ezZ1LhAN/13oTq9Jeu9VvZwWfW5PQHv/UH5h9Dzgjap7DzsDHytTqE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781586770; c=relaxed/simple; bh=KCxdB9tKuM8Ldh97gSu/cGjuHoW55vbxKxPCupj1cXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RaTwAo5Qh6vYNN9aKioX+/ia1XkxuwzSBGgj4YDb5yeaaze6j4TojkLnhMseensVe5jyvUjDh+OOXpnx86SjFmXKF8j1/KPQBE6Go1Se7tAsg8BJ7acK2V4m9ZBcYgx8Zlu8tyvCVxs14fdGWMu0inSuyEe2zDr30zx+E3xU0as= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=tM1nCD71; arc=none smtp.client-ip=74.125.82.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tM1nCD71" Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-304ec41197bso4620903eec.1 for ; Mon, 15 Jun 2026 22:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781586768; x=1782191568; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sCZvnCGRlKO/jFEMUOCjlpNZ45nZwP99ZmU//Z3m5ok=; b=tM1nCD71TetJyAoZcU6wbpGzeebzgst1hHV/EYTA7aglEu5meOkOo3F1MEKHKeDHFb 4jQs26TaJMxa06JD+GYXFafBStMIjEFGR4RuL96CA17RikkqPwIqd9CgXkA3FIYX8xG6 RYcXV41epr3IELliLSvOs9BPY+W3Ib8MiLEtaeuN63DEVZvVAij1t6FWELf9rQhSVcgT MxY1YSrvtAPxlSJ+zdOfbLxmt2cZiNAotyKxH+gcCb3KfREv4CvHONJ5MnFdi3ZsH0K2 L0OnDflLcsy+RAy6b5pLOVGKUBNfuodjShDEUIcL3HVChd+PZ/awL64YFyAvXO6tH+h/ uxZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781586768; x=1782191568; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sCZvnCGRlKO/jFEMUOCjlpNZ45nZwP99ZmU//Z3m5ok=; b=J7Yyv1zhlyKwiKMKDyMKAvYWyTabaE6VO8dOOE1e0IAjo1RMBZd478VgWKGoIzcaOQ aey+yKhIQq/hc8g6ck4Oz2OwKHEX0nis5U9P7JcedO9kvLRbXf4FGB0qhQ0a/GWWFa8W 5ySt5+SuHEdD6MVpM3ywGGat2HazHscnCjPV4Xn8sS0cAeG8hl9O7PB/E2cCqaDYvw3Q GuAPr4EMXYBi53ud01hWr3q11tcBroAStYBE6KZEj5o/LiqdCCLJSsxSr9X/Yd9C7sYc UHS83/MDXvoRsZcem4XEmS8fRK5Dy9TJOzSPNsKTMD2dqrCfXAF826zY4cFcIkVwEzqV 7w8Q== X-Gm-Message-State: AOJu0YzezCmupoyIpA4QVDxpodTPkoAoyaGn6fA95caEx0CEHLXyG2NW AUx5AkQk8lCCJpxB7RDRpjJI2rjuh2yrMfjv+zYGb36zSfThDsap06JD X-Gm-Gg: Acq92OG1NCCVwoEJFeax3bujyMxocAWqQuwbO41YZWqaDJkpynFn4FFyANw2vsEHnr6 t1PPTehLMEpiZ7fT02a4mrMS2X7b42dxF9Icj+as2XEK8bwtFCkdieAFh4SCPtSGvNjAEXAUzhZ mz+GuC3f7oflwZ1FskiVoJo7LOZjYQekmxw0z9hkUkE83kwYW8+TcQ7gJTPpx0/OqYDGJrv7+fo tY5RNxI3lenje9Vojc6DROxrL8jWqqrBg0o/wobhJXSdxZgyGSuCugaVEJNcFq/u7MKmT0XM0Bd 432wh4nkbJ2Q6gml1pxu4uz7A/oXco4zA/V1bdSYLZEIsMqs8Yz+aJirK38BzdYJCh+R9C5qPy/ nVgaVeGtJa3Fs2E3uuZ7RhTVoMoq7NVVM2425KPMm/z/5CQsWzKLkJ8xmrMSMYc+uOdgM1sEmax bLrV4iQTBZWDwWwIdlZ7EpRZqzTLX+DxnLB1qqtN0AimFrqQeLZuGmbB/38eqsFjNrtgF/v3upQ vWLAXVMYsFPP/s= X-Received: by 2002:a05:7300:4346:b0:2ed:e14:e956 with SMTP id 5a478bee46e88-30ba5fce46dmr1210450eec.32.1781586767417; Mon, 15 Jun 2026 22:12:47 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:3714:f5c2:9b83:3df1]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3081ea43b80sm16726052eec.21.2026.06.15.22.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 22:12:46 -0700 (PDT) From: Dmitry Torokhov To: Hans Verkuil , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, sashiko-bot@kernel.org, stable@vger.kernel.org Subject: [PATCH 3/4] Input: sur40 - factor out and move input device initialization Date: Mon, 15 Jun 2026 22:12:31 -0700 Message-ID: <20260616051235.1549517-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog In-Reply-To: <20260616051235.1549517-1-dmitry.torokhov@gmail.com> References: <20260616051235.1549517-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The input device allocation, setup, and registration in sur40_probe() is quite verbose. Factor it out into a helper function sur40_init_input() to improve readability. Additionally, call this helper at the very end of sur40_probe() instead of allocating the input device early. This ensures all video components are fully initialized before the input device is registered (which starts polling), and simplifies the early probe error paths since we don't have to carry and free the input device if probe fails during early V4L2 setup. Reported-by: sashiko-bot@kernel.org Cc: stable@vger.kernel.org Assisted-by: Antigravity:gemini-3.5-flash Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/sur40.c | 91 +++++++++++++++++-------------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c index e9089b0c3e2f..1ad68131e3a6 100644 --- a/drivers/input/touchscreen/sur40.c +++ b/drivers/input/touchscreen/sur40.c @@ -647,6 +647,53 @@ static int sur40_input_setup_events(struct input_dev *input_dev) return 0; } +static int sur40_init_input(struct sur40_state *sur40) +{ + struct input_dev *input; + int error; + + input = input_allocate_device(); + if (!input) + return -ENOMEM; + + /* Set up regular input device structure */ + input->name = DRIVER_LONG; + usb_to_input_id(sur40->usbdev, &input->id); + usb_make_path(sur40->usbdev, sur40->phys, sizeof(sur40->phys)); + strlcat(sur40->phys, "/input0", sizeof(sur40->phys)); + input->phys = sur40->phys; + input->dev.parent = sur40->dev; + + input->open = sur40_open; + input->close = sur40_close; + + error = sur40_input_setup_events(input); + if (error) + goto err_free_input; + + input_set_drvdata(input, sur40); + error = input_setup_polling(input, sur40_poll); + if (error) { + dev_err(sur40->dev, "failed to set up polling\n"); + goto err_free_input; + } + + input_set_poll_interval(input, POLL_INTERVAL); + + error = input_register_device(input); + if (error) { + dev_err(sur40->dev, "Unable to register polled input device.\n"); + goto err_free_input; + } + + sur40->input = input; + return 0; + +err_free_input: + input_free_device(input); + return error; +} + /* Check candidate USB interface. */ static int sur40_probe(struct usb_interface *interface, const struct usb_device_id *id) @@ -655,7 +702,6 @@ static int sur40_probe(struct usb_interface *interface, struct sur40_state *sur40; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; - struct input_dev *input; int error; /* Check if we really have the right interface. */ @@ -676,44 +722,13 @@ static int sur40_probe(struct usb_interface *interface, if (!sur40) return -ENOMEM; - input = input_allocate_device(); - if (!input) { - error = -ENOMEM; - goto err_free_dev; - } - /* initialize locks/lists */ INIT_LIST_HEAD(&sur40->buf_list); spin_lock_init(&sur40->qlock); mutex_init(&sur40->lock); - /* Set up regular input device structure */ - input->name = DRIVER_LONG; - usb_to_input_id(usbdev, &input->id); - usb_make_path(usbdev, sur40->phys, sizeof(sur40->phys)); - strlcat(sur40->phys, "/input0", sizeof(sur40->phys)); - input->phys = sur40->phys; - input->dev.parent = &interface->dev; - - input->open = sur40_open; - input->close = sur40_close; - - error = sur40_input_setup_events(input); - if (error) - goto err_free_input; - - input_set_drvdata(input, sur40); - error = input_setup_polling(input, sur40_poll); - if (error) { - dev_err(&interface->dev, "failed to set up polling"); - goto err_free_input; - } - - input_set_poll_interval(input, POLL_INTERVAL); - sur40->usbdev = usbdev; sur40->dev = &interface->dev; - sur40->input = input; /* use the bulk-in endpoint tested above */ sur40->bulk_in_size = usb_endpoint_maxp(endpoint); @@ -722,7 +737,7 @@ static int sur40_probe(struct usb_interface *interface, if (!sur40->bulk_in_buffer) { dev_err(&interface->dev, "Unable to allocate input buffer."); error = -ENOMEM; - goto err_free_input; + goto err_free_dev; } /* register the video master device */ @@ -790,13 +805,9 @@ static int sur40_probe(struct usb_interface *interface, goto err_free_ctrl; } - /* register the polled input device */ - error = input_register_device(input); - if (error) { - dev_err(&interface->dev, - "Unable to register polled input device."); + error = sur40_init_input(sur40); + if (error) goto err_unreg_video; - } /* we can register the device now, as it is ready */ usb_set_intfdata(interface, sur40); @@ -812,8 +823,6 @@ static int sur40_probe(struct usb_interface *interface, v4l2_device_unregister(&sur40->v4l2); err_free_buffer: kfree(sur40->bulk_in_buffer); -err_free_input: - input_free_device(input); err_free_dev: kfree(sur40); -- 2.54.0.1136.gdb2ca164c4-goog