From patchwork Tue May 31 06:18:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9143399 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5EFE460777 for ; Tue, 31 May 2016 06:21:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53C7A281ED for ; Tue, 31 May 2016 06:21:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 488802821C; Tue, 31 May 2016 06:21:55 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 E0510281ED for ; Tue, 31 May 2016 06:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755356AbcEaGVx (ORCPT ); Tue, 31 May 2016 02:21:53 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36757 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756001AbcEaGUv (ORCPT ); Tue, 31 May 2016 02:20:51 -0400 Received: by mail-pf0-f195.google.com with SMTP id 62so12153810pfd.3; Mon, 30 May 2016 23:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=heAxMrjoNFR/0yk1DCdherH+/r5P2NPRt1jt8vcdnHs=; b=VIv5iTomb5r6dPEQWhWNEGQI84jasXHXraush4JgC0uIuLtygZ23fdDUp2virdJxGd qJoDB9ZMcyHkriDIdhEA6ajcKbUVqxAFyqv+IpVL62rT6gk9DMSNl1pqM4H/MBiWQ9Ue Ji0pEltHN89eVKOhLwTagDxJMsTItuqYuHPoABbwwMcURyPOOq+/2X4S/pzMpkAZHI8q Os++NaKWiPdZ86r7INef9Jsrgr11wZF/25tib9Bed1hrgBDR6EwuEwZWGZJBrEr53ZAb 5p5SPb+y4Iy66BqnHrPXJGylTAywHYTVoO6QcquB22M1E0gvQ23rQVA5yitwMBPaybDn J3lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=heAxMrjoNFR/0yk1DCdherH+/r5P2NPRt1jt8vcdnHs=; b=ADmktyXxoRjo55BnIIYnb7QIP7PZd298W14+aQZuxn2GzkYLqCKuHjMLl0rK+ctl7H F/TuCypDplQrHeron4npoD5QvxpENeHikPo8OWN5nuTVPWLaPnX/ZEl9qZnQ3ShXQBl3 Z/mK+lDe2RFc1zw0fuit1yaQlYVmLDLp1zB8wAsWljeMFgpva9QbNGWWpN319vlTzjie 2Sxn5ccgRgn1PBSMmSD6jvmz3FfzF83HFKAtGHZzRhRc5wYxmlYLHNGXz1MQkwPGEqvs EtQAjpNsJwpUIKqHw8At3RSe88x1qYEkN/cIrEYN8vpP+2yH2rPq5qfHgH1rfReiPLlc yqjw== X-Gm-Message-State: ALyK8tJqHUTs8BcmAAwBP3TWD/oA2Cj/lgQJBsT08INWA9KW8Ku5wgL5g/YJ2xCwr+zrnA== X-Received: by 10.98.6.69 with SMTP id 66mr15030481pfg.115.1464675650206; Mon, 30 May 2016 23:20:50 -0700 (PDT) Received: from localhost ([2601:b00:c501:3660:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id fn3sm51706305pab.20.2016.05.30.23.20.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2016 23:20:49 -0700 (PDT) From: Eduardo Valentin To: Rui Zhang Cc: Linux PM , LKML , Keerthy , Eduardo Valentin Subject: [PATCHv4 47/48] thermal: core: use kzalloc(sizeof(*ptr),...) Date: Mon, 30 May 2016 23:18:54 -0700 Message-Id: <1464675535-2433-48-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464675535-2433-1-git-send-email-edubezval@gmail.com> References: <1464675535-2433-1-git-send-email-edubezval@gmail.com> 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 As a safety check, this patch changes thermal core to check for pointer content size, instead of type size, while allocating memory. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index b3fa47e..792aab7 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -667,8 +667,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, if (lower > upper || upper > max_state) return -EINVAL; - dev = - kzalloc(sizeof(struct thermal_instance), GFP_KERNEL); + dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM; dev->tz = tz; @@ -910,7 +909,7 @@ __thermal_cooling_device_register(struct device_node *np, !ops->set_cur_state) return ERR_PTR(-EINVAL); - cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL); + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); if (!cdev) return ERR_PTR(-ENOMEM); @@ -1155,7 +1154,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp)) return ERR_PTR(-EINVAL); - tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL); + tz = kzalloc(sizeof(*tz), GFP_KERNEL); if (!tz) return ERR_PTR(-ENOMEM);