From patchwork Thu Apr 27 13:33:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88268 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp275361vqo; Thu, 27 Apr 2023 06:39:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58u2mxyrc+l0Nvq83AHiGyZ5Vu1aEUwCxWjmfZwpa+QWgvR8yqhldDlUJMnXqDd6sIWTb6 X-Received: by 2002:a17:902:dac5:b0:1a9:88f2:2816 with SMTP id q5-20020a170902dac500b001a988f22816mr1980562plx.48.1682602791930; Thu, 27 Apr 2023 06:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602791; cv=none; d=google.com; s=arc-20160816; b=BGjnd3v+1Q5qWRvKRDww4ei5PMYt4tUT3MvfOHNjRShu5D3R7J0vd0tHL1e7LhTH7R KtY9Iz0Po7hjkbAKjINTFa/qrmH5+wjfJXLbblIJj5TVsTI4FgGPSRmC3ffch4Yh3Ouc 1zxuV43ggaTBvievDyB8doE9s9ZAxKfvqY9sAUSJkY6CfSz4dSQbfFW/WjreTExaQpNp 5nlWAyOoPFau4TttQlQCm7g1/mqS5cDcKzTRz3EtRYdqxwa1HJG1k6P+S6WVZR0mNrAh s53+aWF8jUzrzwAon69WsEKPgaxMhYsfk2G5vpKB8PegBMOxzQ+luvl6wRpZCdMtm7qM v5jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sSlsn2rCSqBYTsqLNFs5IVZVQwI9t4hKlG0XoLdqEbM=; b=ZxsJCLmFTnZnZqGMzKFsLXR0cM0teBL3bsSkUW/4h5GclR3dGNNPbtzzTIU7D7VM93 42zy5+Ohl3LsPywAuun7VjZHq10IItvk2/ZY9M7XK5qcfRPTh4t1EhV3g8EVmZtIVmPD JEEy3Q2u9kUmsWcgf5P/3OwYFgeKjsFY4TcQ2nz09RDOQhqy1jLw5OvZJ6WaWhCH/Y2y xRZku9F7i75Es3mhK+1s01Qf91t+Jk1YZmjZpVOTJXJQSvzF04cD2Q263JdQmKn90e5k NDHYtk/45q4lZ71EdBu1va5q1dEg2M4I3Vxud6KhUoBh8VkDLegf/kuplItPLhc2upFZ yicw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=cG8jEYqU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t14-20020a1709027fce00b0019a730571dfsi18736469plb.394.2023.04.27.06.39.36; Thu, 27 Apr 2023 06:39:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=cG8jEYqU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243680AbjD0Nd7 (ORCPT + 99 others); Thu, 27 Apr 2023 09:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243373AbjD0Nd4 (ORCPT ); Thu, 27 Apr 2023 09:33:56 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43889F9; Thu, 27 Apr 2023 06:33:55 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E51651FE17; Thu, 27 Apr 2023 13:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602433; h=from:from:reply-to: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=sSlsn2rCSqBYTsqLNFs5IVZVQwI9t4hKlG0XoLdqEbM=; b=cG8jEYqUL5wSr017j5BbELR8ltGqffADlEjIabymVtICVywJkgWtsEBYQWpQ/rrvQuKDTA GEJGd/dm3/uIihq+NwFFJFCs6NKhjfj1TiHOLcFU1KQbWJP4I/ye88GYnDqV+5boEavFr9 8OfNUrQqIOY3Nd/JsHsxAgHNfiHCg7M= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A0B8E138F9; Thu, 27 Apr 2023 13:33:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iBdFJcF5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:53 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 1/8] pwcd_usb: fix error handling in probe Date: Thu, 27 Apr 2023 15:33:43 +0200 Message-Id: <20230427133350.31064-2-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336904929345465?= X-GMAIL-MSGID: =?utf-8?q?1764336904929345465?= If you support only one device, you need to roll back back your counter in all cases if probe() fails. That cannot be left to usb_pcwd_delete() because that must be called conditionally. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index 8202f0a6b093..3a22291d633b 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -606,7 +606,7 @@ static int usb_pcwd_probe(struct usb_interface *interface, struct usb_endpoint_descriptor *endpoint; struct usb_pcwd_private *usb_pcwd = NULL; int pipe; - int retval = -ENOMEM; + int retval = -ENODEV; int got_fw_rev; unsigned char fw_rev_major, fw_rev_minor; char fw_ver_str[20]; @@ -615,7 +615,7 @@ static int usb_pcwd_probe(struct usb_interface *interface, cards_found++; if (cards_found > 1) { pr_err("This driver only supports 1 device\n"); - return -ENODEV; + goto error_count; } /* get the active interface descriptor */ @@ -624,11 +624,12 @@ static int usb_pcwd_probe(struct usb_interface *interface, /* check out that we have a HID device */ if (!(iface_desc->desc.bInterfaceClass == USB_CLASS_HID)) { pr_err("The device isn't a Human Interface Device\n"); - return -ENODEV; + goto error_count; } if (iface_desc->desc.bNumEndpoints < 1) - return -ENODEV; + goto error_count; + /* check out the endpoint: it has to be Interrupt & IN */ endpoint = &iface_desc->endpoint[0].desc; @@ -636,16 +637,17 @@ static int usb_pcwd_probe(struct usb_interface *interface, if (!usb_endpoint_is_int_in(endpoint)) { /* we didn't find a Interrupt endpoint with direction IN */ pr_err("Couldn't find an INTR & IN endpoint\n"); - return -ENODEV; + goto error_count; } /* get a handle to the interrupt data pipe */ pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); /* allocate memory for our device and initialize it */ + retval = -ENOMEM; usb_pcwd = kzalloc(sizeof(struct usb_pcwd_private), GFP_KERNEL); if (usb_pcwd == NULL) - goto error; + goto error_count; usb_pcwd_device = usb_pcwd; @@ -661,13 +663,13 @@ static int usb_pcwd_probe(struct usb_interface *interface, GFP_KERNEL, &usb_pcwd->intr_dma); if (!usb_pcwd->intr_buffer) { pr_err("Out of memory\n"); - goto error; + goto error_delete; } /* allocate the urb's */ usb_pcwd->intr_urb = usb_alloc_urb(0, GFP_KERNEL); if (!usb_pcwd->intr_urb) - goto error; + goto error_delete; /* initialise the intr urb's */ usb_fill_int_urb(usb_pcwd->intr_urb, udev, pipe, @@ -680,7 +682,7 @@ static int usb_pcwd_probe(struct usb_interface *interface, if (usb_submit_urb(usb_pcwd->intr_urb, GFP_KERNEL)) { pr_err("Problem registering interrupt URB\n"); retval = -EIO; /* failure */ - goto error; + goto error_delete; } /* The device exists and can be communicated with */ @@ -723,7 +725,7 @@ static int usb_pcwd_probe(struct usb_interface *interface, retval = register_reboot_notifier(&usb_pcwd_notifier); if (retval != 0) { pr_err("cannot register reboot notifier (err=%d)\n", retval); - goto error; + goto error_delete; } retval = misc_register(&usb_pcwd_temperature_miscdev); @@ -752,10 +754,12 @@ static int usb_pcwd_probe(struct usb_interface *interface, misc_deregister(&usb_pcwd_temperature_miscdev); err_out_unregister_reboot: unregister_reboot_notifier(&usb_pcwd_notifier); -error: +error_delete: if (usb_pcwd) usb_pcwd_delete(usb_pcwd); usb_pcwd_device = NULL; +error_count: + cards_found--; return retval; } From patchwork Thu Apr 27 13:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp275967vqo; Thu, 27 Apr 2023 06:40:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7qirM1p+g2d9hux+bYCZyMCUfxkSUupQwhR56R3TF+xz6WoVBaLRZ17wszbqiQ9ikp2dIJ X-Received: by 2002:a05:6a00:198a:b0:63b:59a7:eafa with SMTP id d10-20020a056a00198a00b0063b59a7eafamr2812491pfl.25.1682602852140; Thu, 27 Apr 2023 06:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602852; cv=none; d=google.com; s=arc-20160816; b=NRoTctt1DOZecF4SfaEWPq4yL2OvduTz9NbfSEgJisa0i5whUwTLiBD9OCzjY9sSro m6yGsXMs0E06AKWr3IdgI3Zu2RYdyPUILpEqGyPpxo2RtTjZt72IDrALSf3x5UyPqkHB B+nRCxuy///oggThearT7+JVIBNvibSOIOc+O6VND7msZeJ9Eyl5E8ClA1OuHEZXzGgY xW//XkwxCofbkm6owNC10m43tub7+Zsz1tXZSSSoxsE3eThyNBYEYKe4Z/VzuArUa8Ti zxKayaO+KqBKRJCNmxQKNiP2GOU3XyFkfFV6umf5Eq1KujEEy96Uah5fAwl1Rk94pNAf WAlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wd+p9adp/HcJc7Th+S4UjCWxhF9jWQwIyXD1bb94NMQ=; b=M/A4ryUATbph5dFyHl5/0mKHCpg/lxLmSx4R9xl50Q7y6p2k1KN1eFAY0eFvRDcrxF XF2GDhFw6E9Z3P9MVuhAxIufNW4gR/GA8Mvqv1GmKOzcypvtNHePzRrzcSckTQ1t/NMe AhTqnDjNU9QhLtcGZr00ZRAsDEmzF9K/4us0WULoVC34UJ61SQxF67/lFRFi8tS5UBrK cBU4JP4Dzl9GIjI3YMM5mkDpFtQZkKSOBmsOWACBLjqtvi+jU1Vf3RPHIOHWTqmGXk0r 2Fl7joGmB+DChWvYIW9wi3kjSBbc3ZCe4q9wjrwg1hfcX3VqZAVMOG21K71ovrSxnw7+ FOAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=AUJ1nVH4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w66-20020a627b45000000b0063b8b7dd46asi18701608pfc.34.2023.04.27.06.40.34; Thu, 27 Apr 2023 06:40:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=AUJ1nVH4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243710AbjD0NeB (ORCPT + 99 others); Thu, 27 Apr 2023 09:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232894AbjD0Nd4 (ORCPT ); Thu, 27 Apr 2023 09:33:56 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BC0C18C; Thu, 27 Apr 2023 06:33:55 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4618921B3F; Thu, 27 Apr 2023 13:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602434; h=from:from:reply-to: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=wd+p9adp/HcJc7Th+S4UjCWxhF9jWQwIyXD1bb94NMQ=; b=AUJ1nVH4EOHXydXh/4AKbyc0BIWTEHLyZn9UrXn55dRnYE47NbYsflM0l2laC2wzXzsGUV sUhG5YzbfNBIo3CEx8HVgSw5Zqw1WFe+DArS7i+h5kaR/66D8dzUNtpSMur3RNjZ30l+3A 7cPnR9bOr8KUt6uidQN1noEaY1HDGwg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 00092138F9; Thu, 27 Apr 2023 13:33:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yF7wOMF5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:53 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 2/8] pcwd_usb: stop open race disconnect Date: Thu, 27 Apr 2023 15:33:44 +0200 Message-Id: <20230427133350.31064-3-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336968088741611?= X-GMAIL-MSGID: =?utf-8?q?1764336968088741611?= There is a mutex already taken in disconnect. And it even has the correct comment. It just has to be taken in open and disconnect, too, to prevent the race. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index 3a22291d633b..d5d68a529620 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -476,14 +476,21 @@ static long usb_pcwd_ioctl(struct file *file, unsigned int cmd, static int usb_pcwd_open(struct inode *inode, struct file *file) { + int retval = -EBUSY; + + mutex_lock(&disconnect_mutex); /* /dev/watchdog can only be opened once */ if (test_and_set_bit(0, &is_active)) - return -EBUSY; + goto error; /* Activate */ usb_pcwd_start(usb_pcwd_device); usb_pcwd_keepalive(usb_pcwd_device); - return stream_open(inode, file); + retval = stream_open(inode, file); + +error: + mutex_unlock(&disconnect_mutex); + return retval; } static int usb_pcwd_release(struct inode *inode, struct file *file) @@ -522,7 +529,13 @@ static ssize_t usb_pcwd_temperature_read(struct file *file, char __user *data, static int usb_pcwd_temperature_open(struct inode *inode, struct file *file) { - return stream_open(inode, file); + int retval; + + mutex_lock(&disconnect_mutex); + retval = stream_open(inode, file); + mutex_unlock(&disconnect_mutex); + + return retval; } static int usb_pcwd_temperature_release(struct inode *inode, struct file *file) From patchwork Thu Apr 27 13:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp273087vqo; Thu, 27 Apr 2023 06:36:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6lKML5llY+D3G3IFWz6Fd583ppQeo26y61jBRGNlOUTVxhvGPPAsj+iG24G1FRv2pT9WWt X-Received: by 2002:a05:6a00:2d21:b0:63c:e253:a692 with SMTP id fa33-20020a056a002d2100b0063ce253a692mr2262813pfb.15.1682602559680; Thu, 27 Apr 2023 06:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602559; cv=none; d=google.com; s=arc-20160816; b=PLx4gY8rXPjtp2tHFMdoH5Q4kbeEadoJs9ZM6vcRLWkUYQ8ccLJb+5n5MdAStbISoJ SckwgJEPkcS/bAnuNUefCgnQhp3gmbBevoqqbbMbU+mbmMJEgYTIIXQrZ259n/2OhzNi 1W5ULqwxIuIiHh+zWFWENIsl74mhIQ4PeWLtpsowSV2Uin9lSmMx7Js/a0iOtz89oAwA so79/ToH3VYhySPYjA36SxsXCLgI82zBgAjm7sRMZX/p/J6n+wcBHrBVSK5sw2rTRCT0 vanleJ2U+0XJmtwmfN//D25/ZeEmZVz9DYF7FXulsjrM4liGe8Z/OlMWq5oNRNsGWptT OXIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XRTL1UYeG/HJ79maMI4g+9suosfMF/LSWnK6uB4WtfE=; b=DvE9wQzRo4MUdhLRlMB4WLoWXcOrG3MHkiKNrRMsl99fE0CMPF7CnoceiNP0+nvzm7 0zFTo+b+A0S/oe/yCu2quJaMcIInWiAg4D0XIhLKhyXP2vC3LkIZoyz7DV7pEQW7cbOo 6jsTfyBcln9847dO0qX0BXNka1bcUVOty4r9hI6BgX/+GLs0xwzoogmwjNfeEFIPJBx3 SnDGFY19iR12RHJqpL5+00YajTILhkMUR2KEp4NALICPWw92ShyB1AwEAaYWePMKv/Nd KUD3id6BsEy1V74cahe6cINMKUyT9kMrDUgFAzMJwRSJsbulOfWfqwbUqLFr21IDrLyC QSTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="d/3a0Ouk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q15-20020aa7982f000000b0063d2540804csi18921523pfl.383.2023.04.27.06.35.46; Thu, 27 Apr 2023 06:35:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="d/3a0Ouk"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243789AbjD0NeK (ORCPT + 99 others); Thu, 27 Apr 2023 09:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243468AbjD0Nd5 (ORCPT ); Thu, 27 Apr 2023 09:33:57 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECF261B6; Thu, 27 Apr 2023 06:33:55 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9CDDC1FE30; Thu, 27 Apr 2023 13:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602434; h=from:from:reply-to: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=XRTL1UYeG/HJ79maMI4g+9suosfMF/LSWnK6uB4WtfE=; b=d/3a0Oukan4rztYhRdqMyyGVTNpRNILrs1urUQIbNYvRpQuwN+C/OELKIISyYEJONEpobn 4mbLLOePgMOH735dCfuAS5I/DAMfiAATTAIsIhswe1/l/6LlfDPM016gqYaLkwghuGTgaT XAdRbXOVk36XN2GFZp3YDmLaDUECmtQ= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 533AC138F9; Thu, 27 Apr 2023 13:33:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IK4BEsJ5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:54 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 3/8] pcwd_usb: usb_pcwd_open handle and return errors Date: Thu, 27 Apr 2023 15:33:45 +0200 Message-Id: <20230427133350.31064-4-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336661689591470?= X-GMAIL-MSGID: =?utf-8?q?1764336661689591470?= Operations on the bus can suffer an IO error. Handle it undoing partial operations and return it to user space Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index d5d68a529620..ed3be8926a15 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -273,7 +273,7 @@ static int usb_pcwd_start(struct usb_pcwd_private *usb_pcwd) if ((retval == 0) || (lsb == 0)) { pr_err("Card did not acknowledge enable attempt\n"); - return -1; + return -EIO; } return 0; @@ -484,10 +484,22 @@ static int usb_pcwd_open(struct inode *inode, struct file *file) goto error; /* Activate */ - usb_pcwd_start(usb_pcwd_device); - usb_pcwd_keepalive(usb_pcwd_device); + retval = usb_pcwd_start(usb_pcwd_device); + if (retval < 0) + goto err_bail; + retval = usb_pcwd_keepalive(usb_pcwd_device); + if (retval < 0) + goto err_bail_and_stop; retval = stream_open(inode, file); + if (retval < 0) + goto err_bail_and_stop; + mutex_unlock(&disconnect_mutex); + return retval; +err_bail_and_stop: + usb_pcwd_stop(usb_pcwd_device); +err_bail: + clear_bit(0, &is_active); error: mutex_unlock(&disconnect_mutex); return retval; From patchwork Thu Apr 27 13:33:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp273018vqo; Thu, 27 Apr 2023 06:35:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6cqDNLUQx+JrUqTZsVdluoQm1UWUNiV1y/oY7bQdXzVsjxtQwHUl5CmAX7Bsri2MtnKO9r X-Received: by 2002:a05:6a21:3294:b0:f2:6fc6:9ca3 with SMTP id yt20-20020a056a21329400b000f26fc69ca3mr2037448pzb.43.1682602552701; Thu, 27 Apr 2023 06:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602552; cv=none; d=google.com; s=arc-20160816; b=BdMcS1IN5IG4BexZevh2N1JdNHsTTtQ/AnxcCAqp3WvwvvNKWgkxU19kjTiHRVmbU9 8Vm6muwNk9HXRo73Vm+Rbo0KBKsGxlTjPv3h45CbZi5q/ogpZFWIV+ihS0rvkSCrR4PT cFN1Jw9dTnMbQy7uu5ZJTAb+Eo4NOFlH4vA2A6tBQIINUu3cPRheW3xZvr//Q+lZF1zC VuDDgVf8e6llpZjRFABDz+LbmDrX8U0iw7t4jKl2I2nMRxi316xSAZ425bLwjXFpKTNO cwny7j0a5Ws7Lz/rQNT7XuFO8ZRBi327AtAatghZyoX+aXnyMTXKEWeU+7QhC8Yyr4pe vObg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=66U18+mtQGCyxXC0M1Viz0RN7ENmrIwJoeJCXyBN1ds=; b=VOceFqfgQCggtlf/iXw8qgMCwiaqPLtyOmuQvnwfCNBzCFfJAm/xh0MUz5ceJFU3t2 PbeLIhIMukgWNzI/xZ1uUDLJYm1vdimeCKH1goftx68Um1NezO0gvRA29XuSOwNEyJVV kgQBBdJy8r7SuXl+t8xnp33l3OLPz/kfV3eSvAOIJl3J6Tope2RtjvnCblGUJVSlgS7S +msoKdQdxkrJvB87dmtLxoZLB3RcGLcCHHPdTt1ayyyTa/Otm/vz/b4huZcxBXRd0Y3Y CUemORegfOgRglIYJfvnU8bcK8r0whjfVbpVl7LBePEWvw5MTpbK9C8IaXEC19wA1KLP v9Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=NmejHtbi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f35-20020a631f23000000b00513cdc43ecfsi18677318pgf.332.2023.04.27.06.35.39; Thu, 27 Apr 2023 06:35:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=NmejHtbi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243767AbjD0NeH (ORCPT + 99 others); Thu, 27 Apr 2023 09:34:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243615AbjD0Nd5 (ORCPT ); Thu, 27 Apr 2023 09:33:57 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52F731B8; Thu, 27 Apr 2023 06:33:56 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0099A1FE31; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602435; h=from:from:reply-to: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=66U18+mtQGCyxXC0M1Viz0RN7ENmrIwJoeJCXyBN1ds=; b=NmejHtbin+lt361qaGQBDureWP0SETBpWpDhTqTc9Y3QRGtPbcvm1Jio13dAjE+KK0DAUQ 0KjV/tLxF5PFRj0jORn7gPVcZALgcLmGAa3SiZ9G6aTu0oxh97D7muMS8eFdDGGoGhFCHw ZE4eKXOKjF9E5RBgjD/xj5p8qbt/uT0= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id ABCC2138F9; Thu, 27 Apr 2023 13:33:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8EkMKMJ5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:54 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 4/8] pcwd_usb: do not leave a freed URB active Date: Thu, 27 Apr 2023 15:33:46 +0200 Message-Id: <20230427133350.31064-5-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336653918901931?= X-GMAIL-MSGID: =?utf-8?q?1764336653918901931?= Fix disconnect so that the URB is killed. Not doing so leaves this to error handling in the case of physical disconnect. This fixes the case of a soft disconnect and prevents multiple accesses to freed memory. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index ed3be8926a15..fe58ec84ce8c 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -815,6 +815,7 @@ static void usb_pcwd_disconnect(struct usb_interface *interface) /* We should now stop communicating with the USB PCWD device */ usb_pcwd->exists = 0; + usb_kill_urb(usb_pcwd->intr_urb); /* Deregister */ misc_deregister(&usb_pcwd_miscdev); From patchwork Thu Apr 27 13:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp273132vqo; Thu, 27 Apr 2023 06:36:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BCUv/MPIbI5MguncqpjQnjI8EnaJbc6qmPLKRf/iu+OYCsSKSrIkc5orwrL5EetkliIQV X-Received: by 2002:a17:90a:bd02:b0:237:ae7c:15be with SMTP id y2-20020a17090abd0200b00237ae7c15bemr1981675pjr.30.1682602564611; Thu, 27 Apr 2023 06:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602564; cv=none; d=google.com; s=arc-20160816; b=r6Kp5MSIpL3JR5GXwLGS8SAHh2mfhtH0fT8U9pJ2gxar45jRWtoiLLveBfL1he4/2I Khx0kS1jkJkOKpiDWpFsv9aQXMQLf71NAKFiEWhsDCAlntAmydyz5Kf9kl46aq+aJe1J vWkidSTcSpn4UVP8rvoR8JfHARY2M06sAQvnL0xCu/US6d9zDSIPanpaffp048mku4Kg QvY2L7xiEct7JBdull2pLPcvFJUsFDUHSF9C80+qARud3SvLEi0utBXmfzgpoHeZ/fW/ BSQMkpVKHXqVVuSKyo72j2c3T3nvERm9yh4LlGWhEGWyHmobbmnZLoKsLwZrZcWobzax E+4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/rGz1l1uLq4Eq57pl2TyE1vJ2RUc3Gpmtm+3jwEAOK8=; b=N+CopjJWL8H4ejwgfVeoXcU/rDb7LtseEiBcf7hkFZDTfRyKVxTmfXzix0k7e0S65q E033DwDp15Cz20/hfqUIVyHNjmUr8QjgL1W1YGPdg6vbp2jjqqC42T4ElWKYoOdg+kvD HeFAd+gdYcrZcbpHS/HtQp2j62LaGOz2hAA5D+deEoFPFaZ8fJshaupskYa+TkgBez68 Wwu6GRdQnR1A3lH/bsKsFV0vKAYwErwRaK7WExeQtHbdkjithnFZdOcPE4DuLDh8Pi/4 1yEabUV5sVyVkJMKcHH/stSFjC8UOOUBoi5FXhavw1SrvpKdiHPRCInBEQ4hkmXFJV61 ziLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=uruuRKW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a63dd50000000b004dccf388f93si17862848pgj.522.2023.04.27.06.35.48; Thu, 27 Apr 2023 06:36:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=uruuRKW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243820AbjD0NeN (ORCPT + 99 others); Thu, 27 Apr 2023 09:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243618AbjD0Nd5 (ORCPT ); Thu, 27 Apr 2023 09:33:57 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0F7E48; Thu, 27 Apr 2023 06:33:56 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4CB0521B40; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602435; h=from:from:reply-to: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=/rGz1l1uLq4Eq57pl2TyE1vJ2RUc3Gpmtm+3jwEAOK8=; b=uruuRKW4koGd2EIxG245KlByD6Z0p4TOVjH06eIK/3BFSDlMs3qxZN4henqSYK1V1ZWSLw PIKqzimQrPYWRnJHsY4z0PPAm3ASCqYxm5uktpUfu8poVS/FUULiBdCjazz9s8umGD3nIJ oc3iVuYN7KWsyBZlMcvwzqUQ/QRPTJo= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 09E93138F9; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yCO+AMN5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:55 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 5/8] pcwd_usb: usb_pcwd_ioctl: return IO errors Date: Thu, 27 Apr 2023 15:33:47 +0200 Message-Id: <20230427133350.31064-6-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336666585533604?= X-GMAIL-MSGID: =?utf-8?q?1764336666585533604?= Reporting back to user space that a watchdog is disabled although it is not due to an IO error is evil. Pass through errors. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index fe58ec84ce8c..b99b8fee2873 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -420,22 +420,30 @@ static long usb_pcwd_ioctl(struct file *file, unsigned int cmd, case WDIOC_SETOPTIONS: { - int new_options, retval = -EINVAL; + int new_options, retval = 0; + int r; + bool specified_something = false; if (get_user(new_options, p)) return -EFAULT; if (new_options & WDIOS_DISABLECARD) { - usb_pcwd_stop(usb_pcwd_device); - retval = 0; + r = usb_pcwd_stop(usb_pcwd_device); + retval = r < 0 ? -EIO : 0; + specified_something = true; } + /* + * technically both options are combinable + * that makes error reporting tricky + */ if (new_options & WDIOS_ENABLECARD) { - usb_pcwd_start(usb_pcwd_device); - retval = 0; + r = usb_pcwd_start(usb_pcwd_device); + retval = retval < 0 ? retval : (r < 0 ? -EIO : 0); + specified_something = true; } - return retval; + return specified_something ? retval : -EINVAL; } case WDIOC_KEEPALIVE: From patchwork Thu Apr 27 13:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp273174vqo; Thu, 27 Apr 2023 06:36:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77jRwpqdSPveRaDX5u0P7uRZLWUXfby9wCcXXwDUQLk55mKBIrm5KTIKAjN2UbnjiuOW+3 X-Received: by 2002:a17:90a:8683:b0:23d:54e8:3bb7 with SMTP id p3-20020a17090a868300b0023d54e83bb7mr2310564pjn.17.1682602568137; Thu, 27 Apr 2023 06:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602568; cv=none; d=google.com; s=arc-20160816; b=zbEDASrpTRWTfxTYw8sn5oEKE4uRC+Ke5DPErMbsT3cLjSQDX4Ci24HlMHDXlbrSMt XmXZn3Dj2wZXbipwZn8SvIMsojAunOE2bntzpGNAGqW3aCCh9/dNX5bUXGqI/6cxfWrX H626SUC5AzX1NtcmMraTkZlwiMRvzhlMZVSusiMmmZrBnZf08ijHojS4I/VlIFeI89wD 9LS48ZRkRG0JFhbVoT3pyykJlDnSPDDLcOudIghZTRzdcKuBXisYaxtsQdwVbo//5uCM nzIb6qHeUMRnxrapuF7ScJyQWSryiT0F7aRRMiQusO/NABv2dHe0rGCxMm2fFT5hBPDY ZNlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NLzP9SAcTfx667WVdFvH1a9kYppCuDAPQTrilwO0dss=; b=LbiT3hL0Sex4YZpZVwO22u1y5ovkJ80I4+HIKRIbXJfk4/iFIlZfKp7bwz1zO+vLPS p+cmDLeVbpigdw0TeylNUzQ3VERapn8/kypraEHz+KVMYm4OEQqKX/Al4y79oOtWbLNf zHXRKCYFaIn0cAR+6PDx8AmmL0DJV08CW4nePUDFG50KUpUGHqHvaSeh3AgOa/oVvmNL lnHSAcXD0W2HHCaSrQE+ELFqlZniOy8Tq4jwQghG59CiaNwdDUkEdL2iWmeOiyPe617p pFpwJ2pU5hMRzScJ8AbB6p0yoNH+pZSf3ityyD4N7foR4Dl6qhkzP4TriI+3+9vm/LH1 JuUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=g45f2Gdv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l7-20020a17090a4d4700b002467a036c62si18723165pjh.45.2023.04.27.06.35.55; Thu, 27 Apr 2023 06:36:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=g45f2Gdv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243799AbjD0NeQ (ORCPT + 99 others); Thu, 27 Apr 2023 09:34:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243628AbjD0Nd5 (ORCPT ); Thu, 27 Apr 2023 09:33:57 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC8F0E6E; Thu, 27 Apr 2023 06:33:56 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9A5D31FE32; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602435; h=from:from:reply-to: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=NLzP9SAcTfx667WVdFvH1a9kYppCuDAPQTrilwO0dss=; b=g45f2GdvxtklIh7pQH298lcsK4S7ATQibFWKbU94QqmzuTHX2+r+dbrvC6anYRZaAVKMdw a1ARvWUWWOsSaJ6/t9QqsccoCgpLpmdzMD5Jue5nukNjXz6KS8pmPBoSquLCOdPbXNQdqk V9K4I/IJPsGdY9zpVWWPL5pKWtrIWUY= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 56C9F138F9; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OEV0E8N5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:55 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 6/8] pcwd_usb: memory ordering of interrupt and waiter Date: Thu, 27 Apr 2023 15:33:48 +0200 Message-Id: <20230427133350.31064-7-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336670495286739?= X-GMAIL-MSGID: =?utf-8?q?1764336670495286739?= The driver manually waits in a loop for an atomic flag. Hence memory ordering must be constrained, so that the waiters read what the interrupt handler writes before it touches the flag. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index b99b8fee2873..50ba88019ed6 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -193,6 +193,7 @@ static void usb_pcwd_intr_done(struct urb *urb) usb_pcwd->cmd_command = data[0]; usb_pcwd->cmd_data_msb = data[1]; usb_pcwd->cmd_data_lsb = data[2]; + smp_wmb(); /* make sure waiters read them */ /* notify anyone waiting that the cmd has finished */ atomic_set(&usb_pcwd->cmd_received, 1); @@ -250,6 +251,7 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd, got_response = 1; } + smp_rmb(); /* ordering with respect to interrupt handler */ if ((got_response) && (cmd == usb_pcwd->cmd_command)) { /* read back response */ *msb = usb_pcwd->cmd_data_msb; From patchwork Thu Apr 27 13:33:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp273277vqo; Thu, 27 Apr 2023 06:36:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7hpdpAPuTvO4dRdtwnRfoNwTWOO4c1LKQDhLS9ByNCJsy36UnEv7uaO6wuQCTi4jkz1g8y X-Received: by 2002:a17:902:e809:b0:1a6:46d7:77f0 with SMTP id u9-20020a170902e80900b001a646d777f0mr7389913plg.0.1682602579491; Thu, 27 Apr 2023 06:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602579; cv=none; d=google.com; s=arc-20160816; b=EmFDjMzTLQ/eEgfyjJyaafnXIfaLtxz2sMVr/0agLiSzytukq+B0xuGy7b4cy1whqn hrHMjUSb4bnLf7P39ELRBXH5a8kqYmlcZQwCYpbe0rYFsK9XRsLCJh1HxAHezpjTeEG2 GjupjEO0N+3iwAfeX4BcMUydkwZO6eeqi+DpLLdzXTasErFfK9lMpao9A1TNbTFkjZsO oMu6KX1xntFg2qZkj8Sq+JFLEvqhh9KL9mkt4SMFo0gVwVOE3bqU9CcjEGhGTZEYWVHl CsKBoBVUpqxcHvg+WaoYp3p7rGG1FyuD4nkSv/S6u6zGocX8BFGq1gawrhCZ3Ya9xaqu jQtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fzOUYOYTdUfKOUVVhjGpyqN36+sVZOkD6XplvoiqEIk=; b=g0DKo1J3kMMFdkYoQWqdqcxR+PmXUlFSTf1IMjYRAsNA0CYd3JakPURJ8H97lgNdxf L2iLT9qM59DEYclPOQLQaXRkUXqrsgwmFtJ34W4zuylCqPgQpyHjMUVBHwLWnYTIklHj CMO1GScSMib3f/d8i2G5pq8d3H7F7l/I3WP0uB9SQcjAJNYBSc6fB2LvgUj8cxgcMG7a fZGsYq8rrzJ4p6N5q30faGlXD/5vYztI390T0Rr9l41ct6w+gWglReY6UDAtWtSUAmCG W3oNWd77FRAhnIk1D4thAovcBfLZcH+uHp9ZwRXdNqieczx7NGOr9hOXUQRFiY6eqP1+ qpnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=RfcGL9hV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020a170902b7ca00b00194a5108613si18078249plz.177.2023.04.27.06.36.06; Thu, 27 Apr 2023 06:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=RfcGL9hV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243839AbjD0NeT (ORCPT + 99 others); Thu, 27 Apr 2023 09:34:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243650AbjD0Nd6 (ORCPT ); Thu, 27 Apr 2023 09:33:58 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40690E72; Thu, 27 Apr 2023 06:33:57 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EB06B1FE34; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602435; h=from:from:reply-to: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=fzOUYOYTdUfKOUVVhjGpyqN36+sVZOkD6XplvoiqEIk=; b=RfcGL9hVqZn+FTge+Biq/qbpy49KMMeI7c6VcIRV5dE3Umqat1BtbwtRO6kBvqqmV/hatr dI/0p3dI1afm9M3FrG7poUIG3dy2Qi/SGPZgXK1y9ji7lHqlK6pejDLPhlCm0f4Jwjc0tB DPFAZ22No0hP+TJI9BeXffmuwffYFKA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A92E7138F9; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mGxhJsN5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:55 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 7/8] usb_pcwd: WDIOC_SETTIMEOUT: prevent preemption Date: Thu, 27 Apr 2023 15:33:49 +0200 Message-Id: <20230427133350.31064-8-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336682476032652?= X-GMAIL-MSGID: =?utf-8?q?1764336682476032652?= Delays between altering the watchdog and giving the keepalive need to be controlled. Do not allow preemption. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index 50ba88019ed6..09cae7a6ad07 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -459,10 +459,14 @@ static long usb_pcwd_ioctl(struct file *file, unsigned int cmd, if (get_user(new_heartbeat, p)) return -EFAULT; - if (usb_pcwd_set_heartbeat(usb_pcwd_device, new_heartbeat)) + preempt_disable(); /* we are on a clock now */ + if (usb_pcwd_set_heartbeat(usb_pcwd_device, new_heartbeat)) { + preempt_enable(); return -EINVAL; + } usb_pcwd_keepalive(usb_pcwd_device); + preempt_enable(); } fallthrough; From patchwork Thu Apr 27 13:33:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 88267 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp273462vqo; Thu, 27 Apr 2023 06:36:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HR9jQ83me971w/hQO2yDX11U3ZQlHN2JhDKFJ9FqC1KjWyPHy0JJyVX4ELRO8sEQx4859 X-Received: by 2002:aa7:8890:0:b0:63b:85a0:142a with SMTP id z16-20020aa78890000000b0063b85a0142amr2599158pfe.3.1682602597652; Thu, 27 Apr 2023 06:36:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682602597; cv=none; d=google.com; s=arc-20160816; b=I9uI8b4ulyIN5bA3BlwSa6sLdvTzkQXKTvPdoB0ilCMI7N9dMhJFWpAKTT/bMlBQZf Bt8Qx2UGaSh1hTl0QLJ/q5e5voVua8Vl3LJ6f0NMrfe3l/uSdVs+9xenduZWysrPtTVw y7FTXmeUw5oQ/qkDge+eWIULIAeJZktjnWNHMIzBU3wRFJd0oh56FSEyymJEpKH+iuYZ aRefFSqvnFpOCwEOIDpJegDZRsr3KKtXPXEuYxiNFv4TmwWLiwJo871cflRJmanhKQWK Hb45cLJJ3TAjNixV90DZTxQe8uJAyzpe64vC5r/FE7yqtSLEgY4C+imC8IVo4OAOSG92 JGng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sKRJAQs2Ndqm7IzSMR+A7rxBU8QW8BdAdffC5PULh3w=; b=T7oDfwZcHV0aTkq2GRT4n7PB0jQkaQJcFmCi2F8cAnB8U9NRikVuOmjsUQQ1XDLqrn NB2KOQz8zfEccHi2/xXppLY1T32Fx/LT/cqQLxXbShXtE/FRtQdJv5hRLJV88hSt/Jpj WYIx5XVZOKdwntC/8/9s1Q1L6ovMROjikfst59adY+WI/fcLAlxNSFFBfiSzu05DvFjO xlpMqvN6qvGWuklWbNBO0aR+LX2t06sOK3HTtaJsk/C+MmfVnJtYRzLNsif9yAU6zlqd 40DAolm8AKYwzdt3j4qAvMF06wcu8pkj047MaNXC0/ckancD1r18LJf9cg7r7AnO661x M2oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=XloF75Ks; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v71-20020a63894a000000b0051a24ba4d74si18137789pgd.837.2023.04.27.06.36.23; Thu, 27 Apr 2023 06:36:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=XloF75Ks; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243846AbjD0NeW (ORCPT + 99 others); Thu, 27 Apr 2023 09:34:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243664AbjD0Nd6 (ORCPT ); Thu, 27 Apr 2023 09:33:58 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A93ACC5; Thu, 27 Apr 2023 06:33:57 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4757E1FE35; Thu, 27 Apr 2023 13:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1682602436; h=from:from:reply-to: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=sKRJAQs2Ndqm7IzSMR+A7rxBU8QW8BdAdffC5PULh3w=; b=XloF75KsTh3J3orK1J0Om5HGNjp5OUXB5yz7v1zQNFL0Sa5F95PKX5D82vj3eIk0i60ABc 7Wpeb3xUf4nblskvjF0LGbrnvvwwRIjM5voi2GpV2VOGeuGG4/2z5UJuX74xa1w5tecqOc JYSSU/85rftkl1xoTHxkI3YsbqcLeKU= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 01B3E138F9; Thu, 27 Apr 2023 13:33:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mAUPOsN5SmSVeQAAMHmgww (envelope-from ); Thu, 27 Apr 2023 13:33:55 +0000 From: Oliver Neukum To: wim@linux-watchdog.org, linux@roeck-us.net, linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Oliver Neukum Subject: [PATCH 8/8] usb_pcwd: remove superfluous usb_device pointer Date: Thu, 27 Apr 2023 15:33:50 +0200 Message-Id: <20230427133350.31064-9-oneukum@suse.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230427133350.31064-1-oneukum@suse.com> References: <20230427133350.31064-1-oneukum@suse.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764336701228817775?= X-GMAIL-MSGID: =?utf-8?q?1764336701228817775?= Retrieve the device from the interface Signed-off-by: Oliver Neukum --- drivers/watchdog/pcwd_usb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index 09cae7a6ad07..055acc191af9 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -112,8 +112,6 @@ static char expect_release; /* Structure to hold all of our device specific stuff */ struct usb_pcwd_private { - /* save off the usb device pointer */ - struct usb_device *udev; /* the interface for this device */ struct usb_interface *interface; @@ -210,6 +208,7 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd, { int got_response, count; unsigned char *buf; + struct usb_device *udev = interface_to_usbdev(usb_pcwd->interface); /* We will not send any commands if the USB PCWD device does * not exist */ @@ -233,7 +232,7 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd, atomic_set(&usb_pcwd->cmd_received, 0); - if (usb_control_msg(usb_pcwd->udev, usb_sndctrlpipe(usb_pcwd->udev, 0), + if (usb_control_msg(udev, usb_sndctrlpipe(udev, 0), HID_REQ_SET_REPORT, HID_DT_REPORT, 0x0200, usb_pcwd->interface_number, buf, 6, USB_COMMAND_TIMEOUT) != 6) { @@ -625,8 +624,10 @@ static struct notifier_block usb_pcwd_notifier = { */ static inline void usb_pcwd_delete(struct usb_pcwd_private *usb_pcwd) { + struct usb_device *udev = interface_to_usbdev(usb_pcwd->interface); + usb_free_urb(usb_pcwd->intr_urb); - usb_free_coherent(usb_pcwd->udev, usb_pcwd->intr_size, + usb_free_coherent(udev, usb_pcwd->intr_size, usb_pcwd->intr_buffer, usb_pcwd->intr_dma); kfree(usb_pcwd); } @@ -691,7 +692,6 @@ static int usb_pcwd_probe(struct usb_interface *interface, usb_pcwd_device = usb_pcwd; mutex_init(&usb_pcwd->mtx); - usb_pcwd->udev = udev; usb_pcwd->interface = interface; usb_pcwd->interface_number = iface_desc->desc.bInterfaceNumber; usb_pcwd->intr_size = (le16_to_cpu(endpoint->wMaxPacketSize) > 8 ?