From patchwork Sat Feb 16 17:06:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 10816315 X-Patchwork-Delegate: viresh.linux@gmail.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20C951390 for ; Sat, 16 Feb 2019 17:06:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AC4029DE8 for ; Sat, 16 Feb 2019 17:06:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDF332B4D6; Sat, 16 Feb 2019 17:06:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8761B29DE8 for ; Sat, 16 Feb 2019 17:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728660AbfBPRGb (ORCPT ); Sat, 16 Feb 2019 12:06:31 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42841 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726258AbfBPRGa (ORCPT ); Sat, 16 Feb 2019 12:06:30 -0500 Received: by mail-pl1-f193.google.com with SMTP id s1so6509454plp.9; Sat, 16 Feb 2019 09:06:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ja6mCcRLlYPsEVUIAvpllb4e3KJQWF+U3raMEkM81WA=; b=n9Dv3YYkhcHJajvQY58H1OcgiXeFtniUh7pwL93X6IO21Pgxy9LsH/hob3e9tTR2B7 NuCfejpyNSGuF7O1nXy6p9jFIldGYL7sWUEyaiUk013K9LE1mfoT/GzcgfWOApEsOiNe y/DhBUFziXR+16MZ0ovyLWx3UYd9LaEupFr2142n91+U2O8jwrUGxo6oj72gwE58Vi7h UhJtjrM9w33PAC9gduL2KOE0CD0TgFSE/gMyZGbDJaEjTDr2VleYZRPOryuE0iFIq0Fd HzbIDE5tPdJBj+W8xWVsd0qq8VGPF5ndFv2Egl+3oBlvI+5vZOGunM0cupEd3+w72yzy hgGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ja6mCcRLlYPsEVUIAvpllb4e3KJQWF+U3raMEkM81WA=; b=MNKNZjO5ngsocbZtP01pqjduRBTPl74sApGmv+RwXaUwG2tA5qajviIbT1mSkeme/m M/YFesnQeNfzvfYnXkGVO0xFdLzEc7VyGjKSzdvcuYLyEczAHczxGlzoI1Vf2+Zv6WJM 1nDFEj/17DCGp3U7QPQPOdJ1+dh3fwLX+vgYeTTPd/eKpVDc/noIGqzAOdqf4Kr5Fevc cntjafi0TL69S/ktHZhjjKi7fHBwKc08nBsH/MtDw+/346P9JXyPu8yoMiiExPrH/3uo +7lZZPXDih2gkauoKvTcXf3qdpbO3iE5KHFzy/LYsE/MaCycyzunyqERZ2WHbJpvVKU/ jlag== X-Gm-Message-State: AHQUAuZcjrifd5vlZgDmsrvIc5EdLMIVc7pfvG633toMo5TNxcQXiBBU SyfxKpsdi/50fva0dZtBQK8= X-Google-Smtp-Source: AHgI3IZfTLoHZuOBTtj+tPGxsaO1d9aaF92QN6NRLj30AVpQyKOBVF5ko/qopM+WhNn1qe49x4D1VA== X-Received: by 2002:a17:902:509:: with SMTP id 9mr15342227plf.94.1550336790185; Sat, 16 Feb 2019 09:06:30 -0800 (PST) Received: from localhost (68.168.130.77.16clouds.com. [68.168.130.77]) by smtp.gmail.com with ESMTPSA id e24sm11644429pfi.153.2019.02.16.09.06.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 16 Feb 2019 09:06:29 -0800 (PST) From: Yangtao Li To: rjw@rjwysocki.net, viresh.kumar@linaro.org, benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au Cc: linux-pm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Yangtao Li Subject: [PATCH] cpufreq: powernv: fix missing check of return value in init_powernv_pstates() Date: Sat, 16 Feb 2019 12:06:23 -0500 Message-Id: <20190216170623.12634-1-tiny.windzz@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP kmalloc() could fail, so insert a check of its return value. And if it fails, returns -ENOMEM. And remove (struct pstate_idx_revmap_data *) to fix coccinelle WARNING by the way. WARNING: casting value returned by memory allocation function to (struct pstate_idx_revmap_data *) is useless. Signed-off-by: Yangtao Li --- drivers/cpufreq/powernv-cpufreq.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c index 7e7ad3879c4e..d2230812fa4b 100644 --- a/drivers/cpufreq/powernv-cpufreq.c +++ b/drivers/cpufreq/powernv-cpufreq.c @@ -244,6 +244,7 @@ static int init_powernv_pstates(void) u32 len_ids, len_freqs; u32 pstate_min, pstate_max, pstate_nominal; u32 pstate_turbo, pstate_ultra_turbo; + int rc = -ENODEV; power_mgt = of_find_node_by_path("/ibm,opal/power-mgt"); if (!power_mgt) { @@ -327,8 +328,11 @@ static int init_powernv_pstates(void) powernv_freqs[i].frequency = freq * 1000; /* kHz */ powernv_freqs[i].driver_data = id & 0xFF; - revmap_data = (struct pstate_idx_revmap_data *) - kmalloc(sizeof(*revmap_data), GFP_KERNEL); + revmap_data = kmalloc(sizeof(*revmap_data), GFP_KERNEL); + if (!revmap_data) { + rc = -ENOMEM; + goto out; + } revmap_data->pstate_id = id & 0xFF; revmap_data->cpufreq_table_idx = i; @@ -357,7 +361,7 @@ static int init_powernv_pstates(void) return 0; out: of_node_put(power_mgt); - return -ENODEV; + return rc; } /* Returns the CPU frequency corresponding to the pstate_id. */