Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp889740rwb; Sat, 1 Oct 2022 10:21:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Lhdz960K5k6HvYwbz1E0RvcXvLD11W7WkLilvdTZkYga9gB3Fwfg6+1ZWomQZ39mNNY8y X-Received: by 2002:aa7:d8cc:0:b0:457:f8be:d5c4 with SMTP id k12-20020aa7d8cc000000b00457f8bed5c4mr12601547eds.261.1664644885941; Sat, 01 Oct 2022 10:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664644885; cv=none; d=google.com; s=arc-20160816; b=XhvMQpoz96R6pbSvgVrQ0ciP4ErSmDGvO1UU/gvUQIfE5b3QCVUfrE4VOt1b7oI0iV UlrrDZnmHMEjAqPqEM2tW17P5ToeQqa0KraQwDS2G0I7/J24w478YOFhESQJaPt1ruE7 jZPT5YN0QsaZ8Kj/vg33tBNOb0qdR4TJ6aJwVmv9WWmy1dXbQhK0QL2X46TS+Y6mkEnr SNlZWdGcqZdaDYmOgUqWw5lLb4o1S7ntabfq6T6Kb355VYxtrK+ZPn9+Wxwfkcvuv6Ph /m1c1cwFXuRY4FasQxEv9QGHVPyMakMlEXoDFaH+O35fRgFRImcw1Zx7i1c+3Cp9LOBx Xkvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=gTWeyuBeEhL5q970/uX9nPUe0s0gUyxTu1xA+Ah5iEY=; b=ewQSMJQ1YPwRzdAEodq0U9jofaBtlo7vEDHFWJywEvQniSL3Qn6zTiyZyquSI4I/Ff qJLhG+ruJ8Os8ddhWk9SEvssYrNOUj0A7sKiVkblykIzDVtVuoEbBTE/xuVMMRa86Q+m ffzOOMs5ARUWPQgg3WI+3qaFLeynuIV9eOqbuJGxRc7ygFjQqHwEv1wB09QBo/VA1gGD inxT0E5t3G+0tebGyzc8EvyslZzv+nwSl1eWgDZlZO453k8ShwiD4Ch1dmvpLTM/bEzS FCvsidMwwdXRXGJe2NLNhBwBlGsw5DUFdweiq+c4WDopVUZbRlXJ9+lZZkbAhNCL5jjA FqOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g2uBr9Pp; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v22-20020a170906381600b007836cf66256si4174345ejc.596.2022.10.01.10.20.58; Sat, 01 Oct 2022 10:21: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=@linaro.org header.s=google header.b=g2uBr9Pp; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229507AbiJARLF (ORCPT + 99 others); Sat, 1 Oct 2022 13:11:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbiJARLE (ORCPT ); Sat, 1 Oct 2022 13:11:04 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F145D5A2DE for ; Sat, 1 Oct 2022 10:11:02 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id z13-20020a7bc7cd000000b003b5054c6f9bso6747574wmk.2 for ; Sat, 01 Oct 2022 10:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=gTWeyuBeEhL5q970/uX9nPUe0s0gUyxTu1xA+Ah5iEY=; b=g2uBr9Pp7Fg69xveOwl6IoppzylYHg7FU3wX/3x9b9enW8WtrSH8jJG8KUxOIZ1vC3 pj/fRv4vdZv69Gzw5ElJkxGBhmkDMEGX97R27fYIqz0DYuVgBT7NLJjoj1t3kDdM9LQw 5GZe4hk13JZqO44HGPsxhUE30grWO/3HWoZeHfbPwZATTYGWQc8PmL0ciwYHWPosNrEL CEzi7nH3NNFl8ssq+axjQ9f9UDfSjEEjQW+EvCATYo9ydeA0ny4wdXvLwHaexjzFRW+n qN8qM0Ah65Zts8b+0dDlan/kcZpdZO10UdON80GiQV9vWCOtk6pxwVWsYwE+Sy/dFbsv 49xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=gTWeyuBeEhL5q970/uX9nPUe0s0gUyxTu1xA+Ah5iEY=; b=q7XYKZlQvZz5aDxhKhxM7Gw+utmitKf9OrySMfhCADg5EFLqLUqFGxx5L1chQ/OByV ELK8lGxZ/2zay0MpxKGPPV7zS7zSiA5BI+vhpd1fL2EvJdy2SQ2/6j+zoIYVk5ih0Ctg qSg8HMc5SpR0+LeGJl7Qr0e9R1IpCTOvSxZ0cyvdh6k6MUnK5XFWtgzIsRGDX5m9V7wk YNA1GdSzAtL5UaS+2Tw+ZqrAyIUal3YC4oF96WQXWIae74YR+q99r5401IxTCKhGC9yw 8jHmZ7friERY2onXTA8o0B3DJed/qjSKos6OI+W9FJGGgMH+UwwWqJfTjvlxTYb+qvDQ qTvQ== X-Gm-Message-State: ACrzQf1IjAVcXkN/AIqgrApTV1qWP5j3C4BksGKAzcTiN9fy5H79au/V HFyhBNBa8o8NRmAlwAmW/lWbBA== X-Received: by 2002:a7b:ce97:0:b0:3b3:4136:59fe with SMTP id q23-20020a7bce97000000b003b3413659femr2236430wmj.24.1664644261573; Sat, 01 Oct 2022 10:11:01 -0700 (PDT) Received: from radium.lan ([88.160.162.107]) by smtp.gmail.com with ESMTPSA id h40-20020a05600c49a800b003b49ab8ff53sm5817641wmp.8.2022.10.01.10.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Oct 2022 10:11:00 -0700 (PDT) From: Fabien Parent To: ilia.lin@kernel.org, agross@kernel.org, bjorn.andersson@linaro.org, rafael@kernel.org, viresh.kumar@linaro.org Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Fabien Parent Subject: [PATCH 1/3] cpufreq: qcom: fix memory leak in error path Date: Sat, 1 Oct 2022 19:10:25 +0200 Message-Id: <20221001171027.2101923-1-fabien.parent@linaro.org> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 If for some reason the speedbin length is incorrect, then there is a memory leak in the error path because we never free the speedbin buffer. This commit fixes the error path to always free the speedbin buffer. Signed-off-by: Fabien Parent --- drivers/cpufreq/qcom-cpufreq-nvmem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c index 863548f59c3e..3bd38acde4b9 100644 --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c @@ -213,6 +213,7 @@ static int qcom_cpufreq_krait_name_version(struct device *cpu_dev, int speed = 0, pvs = 0, pvs_ver = 0; u8 *speedbin; size_t len; + int ret = 0; speedbin = nvmem_cell_read(speedbin_nvmem, &len); @@ -230,7 +231,8 @@ static int qcom_cpufreq_krait_name_version(struct device *cpu_dev, break; default: dev_err(cpu_dev, "Unable to read nvmem data. Defaulting to 0!\n"); - return -ENODEV; + ret = -ENODEV; + goto len_error; } snprintf(*pvs_name, sizeof("speedXX-pvsXX-vXX"), "speed%d-pvs%d-v%d", @@ -238,8 +240,9 @@ static int qcom_cpufreq_krait_name_version(struct device *cpu_dev, drv->versions = (1 << speed); +len_error: kfree(speedbin); - return 0; + return ret; } static const struct qcom_cpufreq_match_data match_data_kryo = { -- 2.37.2