From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C7E7C11F68 for ; Tue, 29 Jun 2021 15:28:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6758F61DD6 for ; Tue, 29 Jun 2021 15:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234818AbhF2Pay (ORCPT ); Tue, 29 Jun 2021 11:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234797AbhF2Pav (ORCPT ); Tue, 29 Jun 2021 11:30:51 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11985C061768 for ; Tue, 29 Jun 2021 08:28:24 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id b5-20020a17090a9905b029016fc06f6c5bso2684440pjp.5 for ; Tue, 29 Jun 2021 08:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=VuuCdU8uAmKGBo8SImwfisVY2Ba0hcixfgMHcrixL7o=; b=AKt8HPsPsJ2ywzYB8tqCs5F9/z9DqNbOFY13/dcY+xCSNrsNs6CYe5lT+IWiyMvkfG fFwovFSVwNF/Hnu1M4O3dYwOKtkE/u7irgBvBu7A0XYi02tOP7U4A0+8DrPRZVw2K7cZ MJGvGNqOh1JkWlbazcA1e1itTxT2tqNkDkqdQUy5TgY84UAr/uuZx1JtTnnrt+G9o5wq hUnaEYBV9xyOXdRMGFXj4Van+AFQU+JUqO5srbSsJNLmT38fjNAJJTJZAXSoHyve4mVV KbLLcF9YxEl0MT893LOlU/erZSMAIDOMX9WwMWGxADL81IrjIpveSAoNjHvHzEFuV4gh nkZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=VuuCdU8uAmKGBo8SImwfisVY2Ba0hcixfgMHcrixL7o=; b=oNEv8RZITbqSd8ZIuYvjsN1rXzjtVpmW/584XypwdoID/FekB3PdrVwR8DSE2UZ9KL GB2F/s/fKBbzCWHMUS+gTkgKxnqiWgB+GO56RQSKvE1WYnj59lYwdgEZXDHnSugWXUd+ W/oUPceeW+VSOBx6SpFJ8L+4aGXWUUTWZDGoRWFOrgTk3eCqOG9wPm0I9dfX4QZeByaR I/y6pBsldDNz2bHl1cLehsfQEV3v7Z1eneLcc7HwHmYAsID4cZ83ukv8+TB2iIQITnjk 9dEAhUt3pO6baqHWdBV3PvhDa0dKBK0apD+/CC/Y4taXQRrO/rGr7ozKzYTjlx0hAzLR KokQ== X-Gm-Message-State: AOAM533b7KMYNCBjR+vqZkZfV9h9KEZasBY19ZHfzPRFYqvw95yh1IZ9 Z2ShjkSg8POJVe9TPKaaTTln X-Google-Smtp-Source: ABdhPJzNywL9BPuI+wsO40c0iGHp9swihEt0eL3tAyyRzrd+pc0kOG4MJpi2KK1UBS2vhuxCv/2jxQ== X-Received: by 2002:a17:90a:390d:: with SMTP id y13mr43719932pjb.133.1624980503512; Tue, 29 Jun 2021 08:28:23 -0700 (PDT) Received: from workstation ([120.138.12.32]) by smtp.gmail.com with ESMTPSA id cs1sm3420299pjb.56.2021.06.29.08.28.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jun 2021 08:28:22 -0700 (PDT) Date: Tue, 29 Jun 2021 20:58:19 +0530 From: Manivannan Sadhasivam To: Matthias Kaehlcke Cc: bjorn.andersson@linaro.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, thara.gopinath@linaro.org, stable@vger.kernel.org Subject: Re: [PATCH] soc: qcom: aoss: Fix the out of bound usage of cooling_devs Message-ID: <20210629152819.GC3580@workstation> References: <20210628172741.16894-1-manivannan.sadhasivam@linaro.org> <20210629042558.GA3580@workstation> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 29, 2021 at 07:17:20AM -0700, Matthias Kaehlcke wrote: > On Tue, Jun 29, 2021 at 09:55:58AM +0530, Manivannan Sadhasivam wrote: > > On Mon, Jun 28, 2021 at 04:03:14PM -0700, Matthias Kaehlcke wrote: > > > > [...] > > > > > > > > > > > A few more previous lines of code for context: > > > > > > int count = QMP_NUM_COOLING_RESOURCES; > > > > > > qmp->cooling_devs = devm_kcalloc(qmp->dev, count, > > > sizeof(*qmp->cooling_devs), > > > GFP_KERNEL); > > > > > > I would suggest to initialize 'count' to 0 from the start and pass > > > QMP_NUM_COOLING_RESOURCES to devm_kcalloc() rather than 'count', > > > instead of resetting 'count' afterwards. > > > > Yeah, I thought about it but the actual bug in the code is not resetting > > the count value to 0. So fixing this way seems a better option. > > I don't agree that it's the better option. IMO it's clearer to pass > the constant QMP_NUM_COOLING_RESOURCES directly to devm_kcalloc(), > rather than giving the impression that the number of allocated items > is variable. Repurposing variables can be confusing and led to this > bug. Also the resulting code doesn't need to re-initialize 'count'. I don't dis-agree with you on this :) Let me send v2 incorporating the comments. Thanks, Mani