Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5247598rwb; Tue, 6 Sep 2022 22:47:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR78k3QWNjyTyqHP466Bt9ywBPlnT1H2nxVMLlRCQWikSZNiDk0LJ3UwOQgTEjVY05J791t2 X-Received: by 2002:a05:6402:1909:b0:447:f0d3:a9b1 with SMTP id e9-20020a056402190900b00447f0d3a9b1mr1732157edz.100.1662529645824; Tue, 06 Sep 2022 22:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662529645; cv=none; d=google.com; s=arc-20160816; b=0FeCpApZ6rZFtcYsMYXNu/EvzwDMEeTpmGRvPzPVi0ZdWdMOR4O+EBanOSphq3ZgwI I3TDJt6FzmALCffaXYvBMcd5tJlw/R4cmfKBuatFZ6OFfD/eG9Wq5ajkekYoEsF7AK9+ a3Gyw4J4OJ4SXoZpCAGhFTHVWpjIy8Fx/z4XeIlVSouxPgvty5Z1kqv/ldQAkdykRgzL uivxQ8K8/hDrGmylmFBHTq8nuy+02ofGm3n4AJk6Gpx0xPMzVQ6n8lEeVWU6eiqusjA0 iwcYXsKFhOaTqMbpwuX2g2Uj5Pq/Afl+EhsQdNMMus7c9BGeTpbVv6ilHmB/ruJok3xK DiAA== 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 :content-language:references:cc:to:user-agent:mime-version:date :message-id:subject:dkim-signature; bh=FsnQRMSSi7+hfFZnWHCqd2bxO6iA2QpxOKTtr1OPJwo=; b=CbCXx4SXNBFj0/eNfcbn2r73OmE7z5+7FnVWH94pYVcEcHiQcepfropmVfbfxK/7XR niq6tAfDnGBsh3Td7a1mq0anw4+FFnaF90XSm4JafKx0IITtAUCLaRAzfnmSvg3BGmL8 jap6aJ19fIITIUIp0kEII7N+3x0gQoq/Y5R9NecWGvwTXk39z25QDZvun5A1B/J4loLR t8OKsGqeS1rshEv3jxo384Z/PJUQtx/2UDs4aKPg8Zf6eAIfdX049//bfzrRS3vjmT1r GpxJCVdTeSa6OGGdpFrYK8JFIpLp6DGq1YxzBTjZ4fkcwAIxBXowKHj1HtJvqGtTqcan u2NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=CtaA0HPv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020a1709066acb00b00734b2821879si9734057ejs.898.2022.09.06.22.47.00; Tue, 06 Sep 2022 22:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=CtaA0HPv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229608AbiIGFP7 (ORCPT + 99 others); Wed, 7 Sep 2022 01:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiIGFP5 (ORCPT ); Wed, 7 Sep 2022 01:15:57 -0400 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D108F696E0; Tue, 6 Sep 2022 22:15:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1662527757; x=1694063757; h=message-id:date:mime-version:to:cc:references:from: in-reply-to:content-transfer-encoding:subject; bh=FsnQRMSSi7+hfFZnWHCqd2bxO6iA2QpxOKTtr1OPJwo=; b=CtaA0HPvfzugS/GJzITilxJRqQC7QJHt84R7uJQSEuE99wlNnhf04qZx rHmXngREjvw326Ty07AFCnUojx6WdSc1HxSwj/sJwiyA/6psWEF1OagtA exqHTkQQuGNAmpl5QZzhDYmJUls3DoXFWMrseR3iB6FduKR2s9MNJpxyB w=; X-IronPort-AV: E=Sophos;i="5.93,295,1654560000"; d="scan'208";a="223930458" Subject: Re: [PATCH v4 06/21] hwmon: (mr75203) fix multi-channel voltage reading Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-54c9d11f.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2022 05:15:42 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-54c9d11f.us-east-1.amazon.com (Postfix) with ESMTPS id D0AD2C08AE; Wed, 7 Sep 2022 05:15:40 +0000 (UTC) Received: from EX19D013UWB004.ant.amazon.com (10.13.138.62) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Wed, 7 Sep 2022 05:15:40 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX19D013UWB004.ant.amazon.com (10.13.138.62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.12; Wed, 7 Sep 2022 05:15:40 +0000 Received: from [192.168.96.145] (10.85.143.173) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.38 via Frontend Transport; Wed, 7 Sep 2022 05:15:37 +0000 Message-ID: <229f0e46-0123-3ffb-d737-0749ffba4e13@amazon.com> Date: Wed, 7 Sep 2022 08:15:36 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 To: Andy Shevchenko CC: , , , , , , , , , , "Farber, Eliav" References: <20220906083356.21067-1-farbere@amazon.com> <20220906083356.21067-7-farbere@amazon.com> Content-Language: en-US From: "Farber, Eliav" In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_SPF_WL autolearn=ham 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 9/6/2022 5:10 PM, Andy Shevchenko wrote: > On Tue, Sep 06, 2022 at 08:33:41AM +0000, Eliav Farber wrote: >> Fix voltage allocation and reading to support all channels in all VMs. >> Prior to this change allocation and reading were done only for the first >> channel in each VM. >> This change counts the total number of channels for allocation, and >> takes >> into account the channel offset when reading the sample data register. > > ... > >> +             total_ch = ch_num * vm_num; >> +             in_config = devm_kcalloc(dev, total_ch + 1, >>                                        sizeof(*in_config), GFP_KERNEL); > > Strictly speaking this should be `size_add(size_mul(...) ...)` > construction > from overflow.h. > >                total_ch = size_mul(ch_num, vm_num); >                in_config = devm_kcalloc(dev, size_add(total_ch, 1), >                                         sizeof(*in_config), GFP_KERNEL); > > Alternatively before doing all these, add a check > >                if (array3_size(ch_num, vm_num, sizeof(*in_config)) < > SIZE_MAX - sizeof(*in_config)) >                        return -EOVERFLOW; > > But this is a bit monstrous. Seems like the above looks and feels better. > > Also for backporting purposes perhaps it's fine to do without using > those macro > helpers. According to the driver code total_ch is a u32 variable while vm_num and ch_num are both limited to a value of 31: #define VM_NUM_MSK GENMASK(20, 16) #define VM_NUM_SFT 16 #define CH_NUM_MSK GENMASK(31, 24) #define CH_NUM_SFT 24 In addition the PVT Controller Series 3+ Specification mentions that the actual maximum values are even smaller – 8 for vm_num and 16 for ch_num. Therefore we are very far from a scenario of an overflow. Do you still think overflow protection in necessary? -- Thanks, Eliav