Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4394418pxb; Mon, 21 Feb 2022 20:09:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYVSCdKq0Aud6SDNBBIrNR2rapVZfKTNF+Y5nSLXVJThmkCTZVEtjhiHtAVR1y6GgC9oDt X-Received: by 2002:a17:903:24a:b0:14f:9dcf:e4b4 with SMTP id j10-20020a170903024a00b0014f9dcfe4b4mr11103645plh.27.1645502956606; Mon, 21 Feb 2022 20:09:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645502956; cv=none; d=google.com; s=arc-20160816; b=Lw7DxJYstbxYMn8B4JEX+hf6wQAS7Jqr7SzdEVDtrt6QYmid4pEuI3G2RHueDWYnB2 Sy4ovQuCdCjA5yIu/hWZo8pkEt4KBOgdSCaI1vTfgSU4+t76p6AwuY8KFnEiyVhoPeFQ ZjdWc+SoA/d83j8f3NMiPDbIjvi5fCt6maXqhYom0inNE+znzZZyGKCAesSujO/RbjDO QasRvx+5Kj+RhjHjVarU87Cd2exeAX6UfRO3sbPrwJRYzgB9vaCjGMc/9/kxVfY8YzbX JWTPgsinAFZliBNUUj8xleqmwBfGRCgKXQrybmLocPrG/oNU2ZqVo7eKbSvlN5GSg/Id piaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ambcHh4g4nuzaHL8tbFi1rXA5xQNyGp2dIP09whVRJw=; b=Bk3wkEuXNSnF0XfJU1H7MqZScjT1TtpinB5mk/ZkqGFqCrc0X5qKTl47/5EdQr7qIh X9hlLZzqpr0JX3tNOn+es/kTfhJnlGbBZ3g7TOizkycWnbFkG3oUG0UqCNpfv+p2hT9U ruTAMYSXIQn4Z+H8vux5nFbO/4JAkkEXFyi08S+i82yaRXI8+1tffSHV/heza5r5NyP/ MdeAyV6cNfe35HE5kzE+fA6PAyo2fTywYwJSzYHCrNbgnmIiK8fUf90pwK1Xopl2XGoP zPWkFMtK93emtYKKVWs0icXrJyYxV+diplwp+As0GxRNB9UwonklKJZspIgJwqElZicq l86w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BQiL3mkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j3si33078379plr.339.2022.02.21.20.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:09:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BQiL3mkh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 03CC26E56E; Mon, 21 Feb 2022 20:09:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231584AbiBUTUm (ORCPT + 99 others); Mon, 21 Feb 2022 14:20:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbiBUTUk (ORCPT ); Mon, 21 Feb 2022 14:20:40 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDBD15F88 for ; Mon, 21 Feb 2022 11:20:16 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id qk11so35793953ejb.2 for ; Mon, 21 Feb 2022 11:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ambcHh4g4nuzaHL8tbFi1rXA5xQNyGp2dIP09whVRJw=; b=BQiL3mkhBFlLDxQtoIqAcV0ab3fcefJxlG9lEU/rFkdNKxHll2gNnfU6QQ/0CvYXhQ oelqyNJ88r0YdQ6lyqQVm6JdWfzVMuWL3A5cByfb2CXg3qCYvRw+wVfAipds3b0pzX5E Lx1aPU3g8MVUxUBRuYwpE2Al7S5hTJ2enK1VT1nHr83WNzNuSjS/tzBx0B0y6CZrXwUK WQZWagQKbhkmbMvQgKld/Ga55nSnSIWPUAh6GhFiFri8GfIacFZs1u7dK1gzJpCwNGGO cVulXnFWWod6FxqKXgEvqLUwkkFtUS6Kj9+K8rt+5OSLXJpaalWhhTI92QIGc0IUtEli 0+Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ambcHh4g4nuzaHL8tbFi1rXA5xQNyGp2dIP09whVRJw=; b=IDYvbiORflKOfvShVXhfLYOyMn/wQjr/du+Dkh88y0mxhRr1CuQ/xJTdGkOXGNmdts hD1cVvWbx/m618BFLZ3DPiguRikFELSoliEW0nOmhmmiYeMqDrU6kIkMmfCOWvCyqWQ0 XTfpBiJgbTpdkDtMo9Sh2nNcyZt4l79UNZo7nij7HIVVLxGBbVytrKBoon9oHAhA7cQJ JrrNGGlG0NKvPlQA4JbxZhHtLHQem6MAdXUE75ufO3w94T2UDFnQpyGyWUPuCepaSakZ TiXAsXlfOfK+L3l663+KYeWjNVLsb+umePBgLoBdFUHh0JK22a3SqqsWQ21XlQNP8PFS 3IQw== X-Gm-Message-State: AOAM532cUn8BTSx55OQQ9JE9bdvSpul7DAXXE9NJVVdaSIAoqnTZLYXF afPCYk1eCIO5ErMQdNi/Roo= X-Received: by 2002:a17:907:1dc4:b0:6ce:a705:9d95 with SMTP id og4-20020a1709071dc400b006cea7059d95mr16735531ejc.597.1645471215416; Mon, 21 Feb 2022 11:20:15 -0800 (PST) Received: from [192.168.0.253] (ip5f5abb8f.dynamic.kabel-deutschland.de. [95.90.187.143]) by smtp.gmail.com with ESMTPSA id m11sm9262546edc.110.2022.02.21.11.20.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Feb 2022 11:20:15 -0800 (PST) Message-ID: <32a2b74b-f541-ddf6-d8c9-6bd6ca0ad07b@gmail.com> Date: Mon, 21 Feb 2022 20:20:14 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH 2/3] staging: r8188eu: refactor rtw_ch2freq() Content-Language: en-US To: Dan Carpenter Cc: Pavel Skripkin , gregkh@linuxfoundation.org, Larry.Finger@lwfinger.net, phil@philpotter.co.uk, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org References: <20220220154847.7521-1-straube.linux@gmail.com> <20220220154847.7521-3-straube.linux@gmail.com> <94160654-ec16-cad2-3cc2-46628caaa17e@gmail.com> <20220221122250.GE3965@kadam> From: Michael Straube In-Reply-To: <20220221122250.GE3965@kadam> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On 2/21/22 13:22, Dan Carpenter wrote: > On Sun, Feb 20, 2022 at 05:30:08PM +0100, Michael Straube wrote: >> On 2/20/22 17:20, Pavel Skripkin wrote: >>> Hi Michael, >>> >>> On 2/20/22 18:48, Michael Straube wrote: >>>> -static int ch_freq_map_num = ARRAY_SIZE(ch_freq_map); >>>> - >>>>   u32 rtw_ch2freq(u32 channel) >>>>   { >>>> -    u8    i; >>>> -    u32    freq = 0; >>>> - >>>> -    for (i = 0; i < ch_freq_map_num; i++) { >>>> -        if (channel == ch_freq_map[i].channel) { >>>> -            freq = ch_freq_map[i].frequency; >>>> -                break; >>>> -        } >>>> -    } >>>> -    if (i == ch_freq_map_num) >>>> -        freq = 2412; >>>> - >>>> -    return freq; >>>> +    return ch_freq_map[channel - 1]; >>>>   } >>> >>> What if channel has wrong value? The old code returned some default >>> value, but with new one we will hit OOB. >>> >> >> Hi Pavel, >> >> thanks for reviewing. Yeah, I thought about adding a check for channel >> value between 1 and 14. But I did not add it because I think if this >> function will ever be called with channel < 1 or channel > 14, then the >> calling code must be wrong. >> >> Would be nice to see what others think about this. > > I'm glad that Pavel noticed this change. This is a risky thing and > should have been noted in the commit message. > > Just from a review stand point it would be best to leave the original > behavior. > Do you mean to leave the whole original code including the 5 GHz frequencies? Or returning a default value if we have a channel value < 1 or > 14? I'm a bit confused now, because Greg asked how we know that the driver is only for 2.4 GHz chips. > I have audited this change and I do not think it is safe. It seems to > me that one way this can be controlled is via > module_param(rtw_channel, int, 0644); in > drivers/staging/r8188eu/os_dep/os_intfs.c. I don't see any checking on > that. > Thank you Dan! I missed that and blindly assumed the function will never be called with channel values OOB. That was not good, sorry. regards, Michael