Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2623819pxb; Sun, 17 Oct 2021 20:49:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZTJTt+wdZQaDWdlVRTDpPYnkmWUuwTMXb+OI5PlmmWOp2SObkVXyV1xtLAGBdjYMGd7PR X-Received: by 2002:a17:90a:5642:: with SMTP id d2mr334664pji.200.1634528955673; Sun, 17 Oct 2021 20:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528955; cv=none; d=google.com; s=arc-20160816; b=Pp+aCzRNfdooBr3a94VZJoj7VtnVWZr5QVzlY1zCYJvyC4Y+j/wzVvFsPmo6uZsoma UKV/d3vkZ5ye0c9nh+FW45931aTisBdkhQqvpRQnoiPPTiQ8t8CAI47I+R5jH0uKJOIk eXBeNCpiXBXvqzjspmtoIBT7qRsbPodZL/xX38jskfQgarTX9ApgKuTmMkfOsMbJerWQ AhSvNT9VP0db18+ekvxlo3IHoA9DC0ohLpOkcS34pP9eF9nYOFrbjtxAOlOuLI+PpXeZ Qsj8Lg4q134nPQv2PNaSU/kxdeBHLBfXVLOgmpeFun/uhlP3t8Ptl8eh2OvChkZUsHlp Z3Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UAYR04dhIfH5S+bn2Qux0e8c7yDxYYlYP/P2nJsD3vU=; b=YG6Rf/xzQH3AgjKz4TeL78vqOqe6DMyJyIzDZ+eZiFgCuUgJYCPnUq3SDucgwqGebQ ybsQNsGYAsf7CwtlODs5q5J/wCxpwEY3bNsYyvfqp5aTxBjYmXJ319jcUvAITh1KUHDV OKQ/ukOuhUT47m0TyYjqT0EUoVW5zU/NAm9xnesamCnVFzghm+uRujydnGbNBGQ1Hbzt jUMzCzYI5zlyTGGo9BI3famWMYeeukTrySZ9aYuGa4VHhwpdmDqMRzER19CVc3YssE7k xRGy9MPv5xqPpx9mZ8ZkiQt8bL4/OnQ3J2AMKnaLduBarstCQpTqgNJ2lKSSbfYnwGxa xUDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AkjuwHpW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v24si20385925pga.524.2021.10.17.20.48.56; Sun, 17 Oct 2021 20:49:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AkjuwHpW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344711AbhJQWBL (ORCPT + 98 others); Sun, 17 Oct 2021 18:01:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242831AbhJQWBK (ORCPT ); Sun, 17 Oct 2021 18:01:10 -0400 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 611FCC06161C; Sun, 17 Oct 2021 14:59:00 -0700 (PDT) Received: by mail-qv1-xf34.google.com with SMTP id m13so9218983qvk.1; Sun, 17 Oct 2021 14:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UAYR04dhIfH5S+bn2Qux0e8c7yDxYYlYP/P2nJsD3vU=; b=AkjuwHpW5R51V84paJ8ElkJ52uNL2z3ED5c5AFGvqSQCac0J2hocQ6qdVeys9Blgzz FVrtWOzbKG89PhNVzqkSyqzkwXsX0JowUg2gFzEqJz9HUMo815ny9KG4WCVKmtiKcy41 mvZDOPEV2SQz9+X6KoMBja2dPhzytWld6YArJ6GaQYDgBhaTDZVFUctGfg+ITaWE/wQu 5BDlFz4CUy5mF2qjKGaxdiOJFrz/8Bag6zIvIhxmMhxu+laKxIFsWZon8U2LZ+Nmv7JR tskL2G2PkjlI2AV8y56hJGb4zUbqAoZr0N/mMeZ09hqI7XOH0UeXyb19jj6eM3avJJUp Z7qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UAYR04dhIfH5S+bn2Qux0e8c7yDxYYlYP/P2nJsD3vU=; b=E1D0zPREyJELJBOR0ThXKCR8z9OpWRDxVJyVsOEF08qkt90564TjwHd01vlbSRTBD6 GRB90ttRCVZp/pJ/rBzaNlVnqJWkWWrf9e3Stu5iP+Rpiw16pZAfDTndlw3sTubS6A/H pXaPaKo1m/+jfq4Tg1nkVZML/74G287Hq0UPDxXOMHG9izAQ5NW9zbEq5JR/DVgzmp6L 5BQm6+gBEuJqJqHrHvmdQ8aFfby0Ld77kDXnlZPMpP8MB996RfXkPxnYG0BougD1Mym9 Fk2TnkEXLYj6cVJyoYG3bqlVIhHM7Vs00YAmVU+LTc8pfPuzFK01RfNnk/6C1aVSGyuO cOsw== X-Gm-Message-State: AOAM532Emx8q8eHPghKIpaLWXJXT2ScOEQIFLT0enLVmZeWyvaroVU0I d5sqfObEhyrh2VIcktTPLPP5uQ6aMJwK658nSbs= X-Received: by 2002:ad4:5bcf:: with SMTP id t15mr22427849qvt.59.1634507939139; Sun, 17 Oct 2021 14:58:59 -0700 (PDT) MIME-Version: 1.0 References: <20210922125939.427-1-caihuoqing@baidu.com> <20211015025815.GA3874@LAPTOP-UKSR4ENP.internal.baidu.com> In-Reply-To: <20211015025815.GA3874@LAPTOP-UKSR4ENP.internal.baidu.com> From: Ping Cheng Date: Sun, 17 Oct 2021 14:58:47 -0700 Message-ID: Subject: Re: [PATCH] HID: wacom: Make use of the helper function devm_add_action_or_reset() To: Jiri Kosina , Benjamin Tissoires , Dmitry Torokhov Cc: Jason Gerecke , Jiri Kosina , Benjamin Tissoires , Linux Input , LKML , Aaron Skomra , "Dickens, Joshua" , caihuoqing@baidu.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I tested the set of two patches. I didn't see any issues with them applied. But, while reviewing the patches, I noticed a minor logic mismatch between the current patch and the original code. I'd hope at least one of the maintainers (Jiri, Benjamin, or Dimitry) reviews this patch, especially the part that I commented below, to make sure that we don't trigger any race condition. Thank you Huoqing, Jason, and the maintainer team! > > From 7adc05783c7e3120028d0d089bea224903c24ccd Mon Sep 17 00:00:00 2001 > > From: Jason Gerecke > > Date: Thu, 14 Oct 2021 07:31:31 -0700 > > Subject: [PATCH] RFC: HID: wacom: Shrink critical section in > > `wacom_add_shared_data` > > > > The size of the critical section in this function appears to be larger > > than necessary. The `wacom_udev_list_lock` exists to ensure that one > > interface cannot begin checking if a shared object exists while a second > > interface is doing the same (otherwise both could determine that that no > > object exists yet and create their own independent objects rather than > > sharing just one). It should be safe for the critical section to end > > once a fresly-allocated shared object would be found by other threads > > (i.e., once it has been added to `wacom_udev_list`, which is looped > > over by `wacom_get_hdev_data`). > > > > This commit is a necessary pre-requisite for a later change to swap the > > use of `devm_add_action` with `devm_add_action_or_reset`, which would > > otherwise deadlock in its error case. > > > > Signed-off-by: Jason Gerecke > > --- > > drivers/hid/wacom_sys.c | 9 ++++----- > > 1 file changed, 4 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c > > index 93f49b766376..62f50e4b837d 100644 > > --- a/drivers/hid/wacom_sys.c > > +++ b/drivers/hid/wacom_sys.c > > @@ -881,8 +881,8 @@ static int wacom_add_shared_data(struct hid_device *hdev) > > if (!data) { > > data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL); > > if (!data) { > > - retval = -ENOMEM; > > - goto out; > > + mutex_unlock(&wacom_udev_list_lock); > > + return -ENOMEM; > > } > > > > kref_init(&data->kref); > > @@ -890,11 +890,12 @@ static int wacom_add_shared_data(struct hid_device *hdev) > > list_add_tail(&data->list, &wacom_udev_list); > > } > > > > + mutex_unlock(&wacom_udev_list_lock); > > + > > wacom_wac->shared = &data->shared; > > > > retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom); > > if (retval) { > > - mutex_unlock(&wacom_udev_list_lock); The mutex_unlock was called after devm_add_action is finished, whether it is a failure or success. The new code calls mutex_unlock before devm_add_action is executed. Is that ok? If there is no concern from the maintainers, the patch has been: Reviewed-by: Ping Cheng Tested-by: Ping Cheng Cheers, Ping > > wacom_remove_shared_data(wacom); > > return retval; > > } > > @@ -904,8 +905,6 @@ static int wacom_add_shared_data(struct hid_device *hdev) > > else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN) > > wacom_wac->shared->pen = hdev; > > > > -out: > > - mutex_unlock(&wacom_udev_list_lock); > > return retval; > > } > > > > -- > > 2.33.0 > > >