Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4729369pxf; Tue, 23 Mar 2021 19:33:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvdMd+EoKNG6/DP/yIsZCo24d0nmQUhgcChrsaApMBPwiomdWcN/MZGvZfQQrvpK0sut+I X-Received: by 2002:a17:906:b015:: with SMTP id v21mr1169085ejy.243.1616553181216; Tue, 23 Mar 2021 19:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616553181; cv=none; d=google.com; s=arc-20160816; b=aieEgf+v4eFhfgmQnHbN5o5Cfjpzo68WsrdS6/fvKWODkz1YKjrqqei2DiYu41tkaK 0rnOkq39jbQ57bdPPJ91zJJiJM83/+/iIejcV7ExBNbcS0LKoIH1j+3wpSKSeVd2U7H2 YndDDDki6x5ktrAMvXAYphs3IymFgo/OGEcwJy8TyaCiwOAcjG83i2nephljLgpZt4H9 O6HMd191j37wmfnCJO6GWVvBVkA7pEP4xvwvoLnVo7viEQnL+a7FH0OweRRU0Zg3V3ai f1oLZVUAkZuYM0j17Q3U+SejENu8CiuYyHnDP/GFUp6/e81d5L65fbLSdcLbwCN2/yoy Ph8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=6Zi8iXZdXiT08WMZwdtUXMNSzkkpWyMEhL8D6TNRRv8=; b=rNBB3/jlmjcc5C1YCAtzFquVWey/MoOtmdD7yC9Ku4HA1Bja7u0DY/MntkVByFhoT6 kawYK02f6/pFm0ENC24kB3/VNQdftJFKQQzd0o0SmUS2UlLlsVK+NCtrvjIEv2tks1uY 8T0Aob8NfIkS0I27G6KD3JxMqxzIuG+yiMgNLaV40fIEot08valpRZq7eQUnDLBDzas2 FV+Nb9NpyHnNfs8BCYrnATOtqhhJ7ZQHPlvLuTSbdwCeIV2DixmfifddxLCHiwlFSi8s hwcUr5qSNv6g4fmECmFND3EKztHPtpcXub0GxDBppSnpkxFc3maV6TldmDnroFF+vjTP zVog== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i25si655658ejf.656.2021.03.23.19.32.38; Tue, 23 Mar 2021 19:33:01 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbhCWOpP (ORCPT + 99 others); Tue, 23 Mar 2021 10:45:15 -0400 Received: from mga02.intel.com ([134.134.136.20]:24410 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232272AbhCWOom (ORCPT ); Tue, 23 Mar 2021 10:44:42 -0400 IronPort-SDR: e7vIaYgQkYeu4XopdFj5IWReMoeLCzYWdX2+xNUt4qoEeEghJn+rr8OvZS3wQzfLRG6/4j8Z6r 4dfa8bAGQM/w== X-IronPort-AV: E=McAfee;i="6000,8403,9931"; a="177613466" X-IronPort-AV: E=Sophos;i="5.81,271,1610438400"; d="scan'208";a="177613466" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2021 07:44:34 -0700 IronPort-SDR: Qbg4TbCdz3qTmD41A4pi6lDDlNVPckD8Tw3EY5/45peH8XlYeYaYR9diw+EC8JLOwhRmLTxrAz PiRBxjzbT5CA== X-IronPort-AV: E=Sophos;i="5.81,271,1610438400"; d="scan'208";a="415017430" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.163]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2021 07:44:29 -0700 Received: by lahna (sSMTP sendmail emulation); Tue, 23 Mar 2021 16:44:26 +0200 Date: Tue, 23 Mar 2021 16:44:26 +0200 From: Mika Westerberg To: lyl2019@mail.ustc.edu.cn Cc: andreas.noever@gmail.com, michael.jamet@intel.com, YehezkelShB@gmail.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Re: [PATCH] thunderbolt: Fix a double put in tb_cfg_read_raw Message-ID: <20210323144426.GY2542@lahna.fi.intel.com> References: <20210323031512.12234-1-lyl2019@mail.ustc.edu.cn> <20210323140647.GV2542@lahna.fi.intel.com> <4ff4aeb5.e6c7.1785f7e4edc.Coremail.lyl2019@mail.ustc.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4ff4aeb5.e6c7.1785f7e4edc.Coremail.lyl2019@mail.ustc.edu.cn> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 23, 2021 at 10:30:16PM +0800, lyl2019@mail.ustc.edu.cn wrote: > > > > > -----原始邮件----- > > 发件人: "Mika Westerberg" > > 发送时间: 2021-03-23 22:06:47 (星期二) > > 收件人: "Lv Yunlong" > > 抄送: andreas.noever@gmail.com, michael.jamet@intel.com, YehezkelShB@gmail.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org > > 主题: Re: [PATCH] thunderbolt: Fix a double put in tb_cfg_read_raw > > > > Hi, > > > > On Mon, Mar 22, 2021 at 08:15:12PM -0700, Lv Yunlong wrote: > > > In tb_cfg_read_raw, req is allocated by tb_cfg_request_alloc() > > > with an initial reference. Before calling tb_cfg_request_sync(), > > > there is no refcount inc operation. tb_cfg_request_sync() > > > calls tb_cfg_request(..,req,..) and if the callee failed, > > > the initial reference of req is dropped and req is freed. > > > > > > Later in tb_cfg_read_raw before the err check, > > > tb_cfg_request_put(req) is called again. It may cause error > > > in race. > > > > Hmm, tb_cfg_request() does tb_cfg_request_get() too and in case of error > > it does tb_cfg_request_put(). So the refcount should be fine. What am I > > missing? > > > > > > > > My patch puts tb_cfg_request_put(req) after the err check > > > finished to avoid unexpected result. > > > > > > Signed-off-by: Lv Yunlong > > > --- > > > drivers/thunderbolt/ctl.c | 4 ++-- > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c > > > index f1aeaff9f368..bb60269c89ab 100644 > > > --- a/drivers/thunderbolt/ctl.c > > > +++ b/drivers/thunderbolt/ctl.c > > > @@ -890,11 +890,11 @@ struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer, > > > > > > res = tb_cfg_request_sync(ctl, req, timeout_msec); > > > > > > - tb_cfg_request_put(req); > > > - > > > if (res.err != -ETIMEDOUT) > > > break; > > > > > > + tb_cfg_request_put(req); > > > + > > > /* Wait a bit (arbitrary time) until we send a retry */ > > > usleep_range(10, 100); > > > } > > > -- > > > 2.25.1 > > > > > I'm very sorry, i was ashamed that i had missed the tb_cfg_request_get() in tb_cfg_request(). It happens, no worries :)