Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1921173pxb; Sat, 7 Nov 2020 03:24:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLPVPiZpLoauf3PFb/PETJAvZJK9Xkj3haZ7ttXg6okM6RBcXWbEwdgitj5e6uToWYbVBU X-Received: by 2002:a17:906:314d:: with SMTP id e13mr6413097eje.412.1604748248479; Sat, 07 Nov 2020 03:24:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604748248; cv=none; d=google.com; s=arc-20160816; b=o+VHfg2yIvGbQ+QAesESSSRCn1zngh4aEv6eRnq0ELkZLwoO5MGnIJJsIGFFSS0a3T 7QbnVU+jLxKlJLbTFebBIuxgpHHzW5AnMEJCaiF4+sNKByZZ4WACtVyWR1dkXJm7ERXl IyaZPvor7tXGdYLL/d5Db05MMJuFGKOv6P+ik1yY6FkfOw4axDTMIDKX71P6xhX/ce4I I+7QZEkaYuSMfnsZm9uFaKH4SuQ8jQ2zQjGRGtNnEu5CJ0QGMeZsowDgJdkW22Hj6j2J ERdvGB/7Du+kkQG2SZn3PugE6uumHkHRfMaaMvFMdCJBUhaGB9xtbeMA90ItZs2QwsI1 OPFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dmarc-filter:sender :dkim-signature; bh=zS6LvfRtNdiUkeSXeykO/m6acIjMHUD9ACoUZ1OClsU=; b=bFlJ35OvF88aZggbqnd2NZC+jjJFB03TSSLhiFbrGTcaGJ3i0gOJNa8TqAdckHnf02 PnKHdCl+xUQUXd+mFXd9CgivSj1XyUALaC1ZtH3Y/K0awsN+i6s3Dei8dp0PGqHDilH4 v2QNj+Q4wOm45rY19TcDCwmEc+muTLn479hZAAKswI7JrJFB1M7tMK/WHXXYHwsAqHVK PxkCuHUz5yWFm4KJVHPrgQLtMGDiSnaPHNgipDu/OPb2KHObD07BGjFbi/6ot58gMTOO YFV+l5uZEtEoW7AO2t1mn+lQUO3uDagn3vMBBt1QE/6KL0Jmh9So2zZgTSYAwgCHHanj fZJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=lEV7M0v9; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cd24si2872558ejb.213.2020.11.07.03.23.44; Sat, 07 Nov 2020 03:24:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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=@mg.codeaurora.org header.s=smtp header.b=lEV7M0v9; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726242AbgKGLXi (ORCPT + 99 others); Sat, 7 Nov 2020 06:23:38 -0500 Received: from m42-4.mailgun.net ([69.72.42.4]:46503 "EHLO m42-4.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbgKGLXi (ORCPT ); Sat, 7 Nov 2020 06:23:38 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1604748217; h=Content-Type: MIME-Version: Message-ID: In-Reply-To: Date: References: Subject: Cc: To: From: Sender; bh=zS6LvfRtNdiUkeSXeykO/m6acIjMHUD9ACoUZ1OClsU=; b=lEV7M0v96vUpSesS3ls9jsFDkuQWbMxBJrr2X1yV+CzAAy8X3MSnEFfoOTdWZqTnED3QQKxl OrdLdeJj7PU+KKjADu/N+vR47KTAdVjsTtquwKHFLNshGWP0n5xQSy0pdyiHi4UPlQB1dSyI owM06X8AlLaGoHnm6s0/QxYP/dM= X-Mailgun-Sending-Ip: 69.72.42.4 X-Mailgun-Sid: WyI3YTAwOSIsICJsaW51eC13aXJlbGVzc0B2Z2VyLmtlcm5lbC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n07.prod.us-west-2.postgun.com with SMTP id 5fa683b861a7f890a693db05 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Sat, 07 Nov 2020 11:23:36 GMT Sender: kvalo=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id D53BAC433F0; Sat, 7 Nov 2020 11:23:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from potku.adurom.net (88-114-240-156.elisa-laajakaista.fi [88.114.240.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: kvalo) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2A814C433C6; Sat, 7 Nov 2020 11:23:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2A814C433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=kvalo@codeaurora.org From: Kalle Valo To: Alex Dewar Cc: netdev@vger.kernel.org, Carl Huang , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , ath11k@lists.infradead.org, Jakub Kicinski Subject: Re: [PATCH 2/2] ath11k: Handle errors if peer creation fails References: <20201004100218.311653-1-alex.dewar90@gmail.com> <87blhfbysb.fsf@codeaurora.org> <20201006081321.e2tf5xrdhnk4j3nq@medion> Date: Sat, 07 Nov 2020 13:23:30 +0200 In-Reply-To: <20201006081321.e2tf5xrdhnk4j3nq@medion> (Alex Dewar's message of "Tue, 6 Oct 2020 09:13:21 +0100") Message-ID: <87pn4pfm19.fsf@codeaurora.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Alex Dewar writes: > On Tue, Oct 06, 2020 at 10:26:28AM +0300, Kalle Valo wrote: >> Alex Dewar writes: >> >> > ath11k_peer_create() is called without its return value being checked, >> > meaning errors will be unhandled. Add missing check and, as the mutex is >> > unconditionally unlocked on leaving this function, simplify the exit >> > path. >> > >> > Addresses-Coverity-ID: 1497531 ("Code maintainability issues") >> > Fixes: 701e48a43e15 ("ath11k: add packet log support for QCA6390") >> > Signed-off-by: Alex Dewar >> > --- >> > drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++------------ >> > 1 file changed, 9 insertions(+), 12 deletions(-) >> > >> > diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c >> > index 7f8dd47d2333..58db1b57b941 100644 >> > --- a/drivers/net/wireless/ath/ath11k/mac.c >> > +++ b/drivers/net/wireless/ath/ath11k/mac.c >> > @@ -5211,7 +5211,7 @@ ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, >> > struct ath11k *ar = hw->priv; >> > struct ath11k_base *ab = ar->ab; >> > struct ath11k_vif *arvif = (void *)vif->drv_priv; >> > - int ret; >> > + int ret = 0; >> >> I prefer not to initialise the ret variable. >> >> > arvif->is_started = true; >> > >> > /* TODO: Setup ps and cts/rts protection */ >> > >> > - mutex_unlock(&ar->conf_mutex); >> > - >> > - return 0; >> > - >> > -err: >> > +unlock: >> > mutex_unlock(&ar->conf_mutex); >> > >> > return ret; >> >> So in the pending branch I changed this to: >> >> ret = 0; >> >> out: >> mutex_unlock(&ar->conf_mutex); >> >> return ret; >> >> Please check. > > I'm afraid you've introduced a bug ;). The body of the first if-statement > in the function doesn't set ret because no error has occurred. So now > it'll jump to the label and the function will return ret uninitialized. Ouch, so I did. Good catch! I would have hoped that GCC warns about that but it didn't. I fixed the bug and added also a warning messages if peer_create() fails: https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/commit/?h=pending&id=e3e7b8072fa6bb0928b9066cf76e19e6bd2ec663 Does this look better now? :) > With the gcc extension, ret will be initialised to zero anyway, so we're > not saving anything by explicitly assigning to ret later in the > function. I prefer not to initialise ret in the beginning of the function and I try to maintain that style in ath11k. I think it's more readable that the error value is assigned just before the goto. -- https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches