Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp452944pxk; Thu, 24 Sep 2020 09:30:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwld7zPaDSQucWIiXuFT0HHHzeg+NNkiip+gBuYV731dTujq0p4A48380Nlv1PSUl7hUjQi X-Received: by 2002:aa7:cf05:: with SMTP id a5mr735509edy.313.1600965004495; Thu, 24 Sep 2020 09:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600965004; cv=none; d=google.com; s=arc-20160816; b=pYkIKCnmgQthYpJcJ3cfzRA0WKDNgY3gtIC6IpIxWqueViKhH2yQTV8mJq/JFwGS8L CRxFNjqkPqpz9hChcZOg2W6YNtzNZNLDKWFdx2OCbPgsAUDTyRXIwHsviU0pQ6fevULZ aqh500v6EXhLWXCGODFEU6KNetQ3aQxKzGbNswLy+lXV+/bYM8uSZ3/FstzGieschPJv EXY1XDwVOIJVcAWgyfSa5BGVVfb7KK1q2zsTZ81VXCq1qNgSPDzBc7v3RGMWSzzH77y8 /PczYRmJYS+AsbR4bXzGqa7cn6W6+cyhGeQABiEse8ywXyyD9toxuU8TWbM0vhsqw9pg KJfw== 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=H7xOaaB817aiULShu/d8nxmq9YAErkwo2R+VMgY3kb4=; b=S68HsYNJ6Hg7zCtvpF7OlxELzgsp9e+11sFneFRgpguE6p5SM3guuxiwrviUT3K53+ +2x+m9gRNICx0Cf7W7CJUCZL3MqYSwqvRQqI53W6nq3YcTB7p3dgLufFpskHVkovjSQh e4BkYn2Y6Y1EQ/coX02Wwza4Zuf5MKHDlzsyfyWchiRFKwiNudbb9EiZQnnH4U3flS3W T5FulaTl7zqmWLPd9VzGpQrriFvCuteP7idOkOK3mCnq8bkxKxmW/Yj/apsC40TEMmvC UYzJFlxKVC2txTg4SnScPGtCilFi4omxs/GQTdHgXVUYlYj4/HD9Pxe/ynYHE9bRd+l3 ESXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=oKFAVSI3; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p25si2487023edt.332.2020.09.24.09.29.41; Thu, 24 Sep 2020 09:30:04 -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=@mg.codeaurora.org header.s=smtp header.b=oKFAVSI3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728589AbgIXQ1q (ORCPT + 99 others); Thu, 24 Sep 2020 12:27:46 -0400 Received: from z5.mailgun.us ([104.130.96.5]:25298 "EHLO z5.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728581AbgIXQ1o (ORCPT ); Thu, 24 Sep 2020 12:27:44 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1600964863; h=Content-Type: MIME-Version: Message-ID: In-Reply-To: Date: References: Subject: Cc: To: From: Sender; bh=H7xOaaB817aiULShu/d8nxmq9YAErkwo2R+VMgY3kb4=; b=oKFAVSI33lHC8MB1kCm9lPNXydrP78baE3OQEHdN9TErdDMR2q+19hrQ4cbbLpcLPEY9/Df4 0tMoUUhhRCFCav6ykjLS50ApAEMCzmbwt7ufEUR0HZ7+5dAfDb+GKsxPPvfEBQMYhj6F5er/ uGV7bOU364xkc6Rz2Pf0C4iaCHg= X-Mailgun-Sending-Ip: 104.130.96.5 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd 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-east-1.postgun.com with SMTP id 5f6cc8ff89f51cb4f12ab143 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 24 Sep 2020 16:27:43 GMT Sender: kvalo=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 7FAC3C433A0; Thu, 24 Sep 2020 16:27:42 +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, URIBL_BLOCKED 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 F2382C433FF; Thu, 24 Sep 2020 16:27:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org F2382C433FF 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: Julian Calaby Cc: Alex Dewar , netdev@vger.kernel.org, linux-wireless@vger.kernel.org, LKML , ath10k@lists.infradead.org, Jakub Kicinski , Saeed Mahameed , "David S. Miller" Subject: Re: [PATCH v2] ath10k: sdio: remove redundant check in for loop References: <20200916165748.20927-1-alex.dewar90@gmail.com> Date: Thu, 24 Sep 2020 19:27:36 +0300 In-Reply-To: (Julian Calaby's message of "Thu, 17 Sep 2020 10:45:33 +1000") Message-ID: <87h7rnnnrb.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-kernel@vger.kernel.org Julian Calaby writes: > On Thu, Sep 17, 2020 at 3:09 AM Alex Dewar wrote: >> >> The for loop checks whether cur_section is NULL on every iteration, but >> we know it can never be NULL as there is another check towards the >> bottom of the loop body. Refactor to avoid this unnecessary check. >> >> Also, increment the variable i inline for clarity > > Comments below. > >> Addresses-Coverity: 1496984 ("Null pointer dereferences) >> Suggested-by: Saeed Mahameed >> Signed-off-by: Alex Dewar >> --- >> v2: refactor in the manner suggested by Saeed >> >> drivers/net/wireless/ath/ath10k/sdio.c | 12 +++--------- >> 1 file changed, 3 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/net/wireless/ath/ath10k/sdio.c b/drivers/net/wireless/ath/ath10k/sdio.c >> index 81ddaafb6721..486886c74e6a 100644 >> --- a/drivers/net/wireless/ath/ath10k/sdio.c >> +++ b/drivers/net/wireless/ath/ath10k/sdio.c >> @@ -2307,8 +2307,8 @@ static int ath10k_sdio_dump_memory_section(struct ath10k *ar, >> } >> >> count = 0; >> - >> - for (i = 0; cur_section; i++) { >> + i = 0; >> + for (; cur_section; cur_section = next_section) { > > You can have multiple statements in each section of a for() if you need to, e.g. > > for (i = 1; cur_section; cur_section = next_section, i++) { > > which means that the increment of i isn't hidden deep in the function body. Yeah, I was thinking the same. But I'll apply this patch anyway, it's still an improvement. > That said, this function is a mess. Something (approximately) like > this might be more readable: > > prev_end = memregion->start; > for (i = 0; i < mem_region->section_table.size; i++) { > cur_section = &mem_region->section_table.sections[i]; > > // fail if prev_end is greater than cur_section->start - message > from line 2329 and 2294 > // check section size - from line 2315 > > skip_size = cur_section->start - prev_end; > > // check buffer size - from line 2339 - needs to account for the > skip size too. > // fill in the skip size amount - from line 2358 and 2304 > // ath10k_sdio_read_mem - from line 2346 > > prev_end = cur_section->end; > } I agree. Anyone can come up with a patch? -- https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches