Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4552295pxv; Tue, 29 Jun 2021 09:36:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0IFg70xJRVj+VH0mKzbvDcuDFW8gNM4lG1rXellNEXXALJ4ayV5p5povcNLKpt2hNElKR X-Received: by 2002:a50:935a:: with SMTP id n26mr41853806eda.8.1624984611922; Tue, 29 Jun 2021 09:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624984611; cv=none; d=google.com; s=arc-20160816; b=e/+v25enM1g1PmIbQgdIeOCKkjON3K6WIvMlehEeMctYTLHwnR7EseedhG8EkC9Y8S ArwAVAxicQiAAWRi9H2fUN4FxS+cpT5IlNXRhdt/VsbqnU2b7oszWrA7feLu/wJZIMwC P1sNkqJHMDEeewhTT2TdbCgOMndO6OmCmRtfZ9Gpp1Y2Q4YSyrZOc2nr1XEBgVSpsDM6 hY+nAmVztFRp+wvfx4JNO82t6WDL909x8oe2gcOB+N44clhmo6GDShL3pkykQdRD3LXi At+8p4ZwXKpYQLMTSxUJ3DvCcdf9eGChokQkIdnmCLFiMYrbGQuNXuVzvvEwwD0uRBgY rwng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=VuuCdU8uAmKGBo8SImwfisVY2Ba0hcixfgMHcrixL7o=; b=oYjeMViVasAvcqqOULvO/6c35xnpvoSxTdKJRzJ5OyZXvWHyfQnbGyHBNh8wsWFQis kDmc/WM3EfHCdDEPETAP15HmxZmi2VVmIv6oOP+bKwfsQtB6wxWib45BfqT7ohG+RY/+ paPNfOu+xO4/80dRaGqnXnUeMJ/+UR2rZlUMu/t/aMFWWr9Z0GFgqte61qPSQudaD5D+ jGx+rbNRTBh51NQ0pWP1IwfYWR6zkXJNRicLViA/qmMFd/NqSxBub8pQnRHM+s6MSPNN l4T9uMn65zZk0cjDJfUF2kKcItQRRYdw/hAu5CSpg15dAlEqQbKbwlC44T/HcXC4RRtO cVew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AKt8HPsP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si625065edx.331.2021.06.29.09.36.29; Tue, 29 Jun 2021 09:36:51 -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=@linaro.org header.s=google header.b=AKt8HPsP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234802AbhF2Pax (ORCPT + 99 others); Tue, 29 Jun 2021 11:30:53 -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-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