From patchwork Wed Jan 2 15:29:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 1924651 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 306953FE37 for ; Wed, 2 Jan 2013 15:31:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752780Ab3ABPbO (ORCPT ); Wed, 2 Jan 2013 10:31:14 -0500 Received: from devils.ext.ti.com ([198.47.26.153]:39987 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752755Ab3ABPbO (ORCPT ); Wed, 2 Jan 2013 10:31:14 -0500 Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id r02FVCj3014134; Wed, 2 Jan 2013 09:31:12 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r02FVCMs014887; Wed, 2 Jan 2013 09:31:12 -0600 Received: from dlelxv23.itg.ti.com (172.17.1.198) by dfle73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.1.323.3; Wed, 2 Jan 2013 09:31:11 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with ESMTP id r02FVCwO027309; Wed, 2 Jan 2013 09:31:12 -0600 Received: from localhost (h64-4.vpn.ti.com [172.24.64.4]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id r02FVAw16737; Wed, 2 Jan 2013 09:31:10 -0600 (CST) From: Eduardo Valentin To: CC: , , , Eduardo Valentin Subject: [PATCH RESEND 4/4] thermal: check for invalid trip setup when registering thermal device Date: Wed, 2 Jan 2013 17:29:42 +0200 Message-ID: <1357140582-8151-5-git-send-email-eduardo.valentin@ti.com> X-Mailer: git-send-email 1.7.7.1.488.ge8e1c In-Reply-To: <1357140582-8151-1-git-send-email-eduardo.valentin@ti.com> References: <1357140582-8151-1-git-send-email-eduardo.valentin@ti.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This patch adds an extra check in the data structure while registering a thermal device. The check is to avoid registering zones with a number of trips greater than zero, but with no .get_trip_temp nor .get_trip_type callbacks. Receiving such data structure may end in wrong data access. Signed-off-by: Eduardo Valentin Reviewed-by: Durgadoss R --- drivers/thermal/thermal_sys.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c index fba27c3..0a1bf6b 100644 --- a/drivers/thermal/thermal_sys.c +++ b/drivers/thermal/thermal_sys.c @@ -1530,6 +1530,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, if (!ops || !ops->get_temp) return ERR_PTR(-EINVAL); + if (trips > 0 && !ops->get_trip_type) + return ERR_PTR(-EINVAL); + tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL); if (!tz) return ERR_PTR(-ENOMEM);