From patchwork Tue Nov 8 05:09:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416647 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 3735360512 for ; Tue, 8 Nov 2016 06:06:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2660028BDB for ; Tue, 8 Nov 2016 06:06:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 189FB28BE0; Tue, 8 Nov 2016 06:06:06 +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 85CFA28BDB for ; Tue, 8 Nov 2016 06:06:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753306AbcKHGGE (ORCPT ); Tue, 8 Nov 2016 01:06:04 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34989 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753302AbcKHGGD (ORCPT ); Tue, 8 Nov 2016 01:06:03 -0500 Received: by mail-pf0-f193.google.com with SMTP id i88so18195113pfk.2; Mon, 07 Nov 2016 22:06:03 -0800 (PST) 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=Ed6d6kDi78ACr70UK00kMka6S7MiRpVeyODUJWnvp70=; b=GR3wsATxVFwF153/hrMMLexCNQy8bGBUb8YwQiCbaXpNBZOLPeFfVYTxp0aTP+HJ3r /dv+LBJ2fYpyrwBfHWjhsxc7EBLNhHsfbaq26u+k8i4+10yy/9Yy99Mi49WKd4xUKFEp y4+ZPA8zifWhqBJPCXLD3dwtajJv6dCzXKl01I5SwREqpjKA2nsc7iXV0HCcYsmge70g lvF9tcZToE2Mb5iyPeV6EINa3S9k9c8aJEQeK7No8AkD1h+RSc60Q1qy6lihNI/sjDe+ Uph4BZGDdi0QcK8M08OZiOKrBdIQZS9+jDHRRFuRNkD2nrGwdm26HM2zSvT4GMjG+TQ2 DMqQ== 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=Ed6d6kDi78ACr70UK00kMka6S7MiRpVeyODUJWnvp70=; b=eClr1YhL4K2OLF9mG2lWXDYz1JMsvDEnp3xm2rONVcCXH+uQhhPLxvYPLV1MX+/OHg GioK2ABBmlsF5D2s1mMp3a2oSviasGIWBqbAL6bHG77c+i96/0uS6/f19hsanyZ2GVxv EddrjXlmDrM5/PUB1fwci7wczWGgYeu2bg7mV4ownqqYI04z2B0Y111NFSFA2Onw6TdI LBBZ/Us6aERUzwZAu5vZaYrW+8AYUlO4lOhOKmLf1CrcmXCEbyAJY454MWHzdFQlGTl9 Qg1ErgUzDbu5ZGOJ1WBeurPPkY+UEwsky1OCf8WV/dd2CQfSYExpxDswhK2pD6ld6flw RJig== X-Gm-Message-State: ABUngveO+GaOvwpiYaQb3KOMeLfFpX1F4rrDZ32uoJzf4NgFGEsAxFH8uyUE+YZwJcsdCA== X-Received: by 10.98.194.130 with SMTP id w2mr19929434pfk.143.1478581877375; Mon, 07 Nov 2016 21:11:17 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id zf9sm20457325pac.12.2016.11.07.21.11.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:11:16 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 47/49] thermal: core: use kzalloc(sizeof(*ptr),...) Date: Mon, 7 Nov 2016 21:09:25 -0800 Message-Id: <1478581767-7009-48-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-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 2db21e5..4f93844 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -674,8 +674,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; @@ -917,7 +916,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); @@ -1163,7 +1162,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);