From 402673e9a0bc34b5f6bd31a87d176317145232b0 Mon Sep 17 00:00:00 2001 From: Siddartha Mohanadoss Date: Fri, 6 Jan 2012 16:31:44 -0800 Subject: [PATCH] hwmon: pm8xxx-adc: Fix reading sysfs for vbatt The memory where the sysfs attribute is stored on initialization gets overwritten causing invalid length on the vbatt sysfs reading. Fix it by removing the dynamic memory allocation for BTM parameters. Change-Id: If8b88c9460b0018a159688b5ba28798d97e0b0b6 Signed-off-by: Siddartha Mohanadoss --- drivers/hwmon/pm8xxx-adc.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/hwmon/pm8xxx-adc.c b/drivers/hwmon/pm8xxx-adc.c index 57d34b93b7f..5f8faee2300 100644 --- a/drivers/hwmon/pm8xxx-adc.c +++ b/drivers/hwmon/pm8xxx-adc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Code Aurora Forum. All rights reserved. + * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -145,7 +145,7 @@ struct pm8xxx_adc { struct wake_lock adc_wakelock; int msm_suspend_check; struct pm8xxx_adc_amux_properties *conv; - struct pm8xxx_adc_arb_btm_param batt[0]; + struct pm8xxx_adc_arb_btm_param batt; struct sensor_device_attribute sens_attr[0]; }; @@ -451,8 +451,8 @@ static void pm8xxx_adc_btm_warm_scheduler_fn(struct work_struct *work) spin_lock_irqsave(&adc_pmic->btm_lock, flags); warm_status = irq_read_line(adc_pmic->btm_warm_irq); - if (adc_pmic->batt->btm_warm_fn != NULL) - adc_pmic->batt->btm_warm_fn(warm_status); + if (adc_pmic->batt.btm_warm_fn != NULL) + adc_pmic->batt.btm_warm_fn(warm_status); spin_unlock_irqrestore(&adc_pmic->btm_lock, flags); } @@ -465,8 +465,8 @@ static void pm8xxx_adc_btm_cool_scheduler_fn(struct work_struct *work) spin_lock_irqsave(&adc_pmic->btm_lock, flags); cool_status = irq_read_line(adc_pmic->btm_cool_irq); - if (adc_pmic->batt->btm_cool_fn != NULL) - adc_pmic->batt->btm_cool_fn(cool_status); + if (adc_pmic->batt.btm_cool_fn != NULL) + adc_pmic->batt.btm_cool_fn(cool_status); spin_unlock_irqrestore(&adc_pmic->btm_lock, flags); } @@ -860,7 +860,7 @@ uint32_t pm8xxx_adc_btm_configure(struct pm8xxx_adc_arb_btm_param *btm_param) if (rc < 0) goto write_err; - adc_pmic->batt->btm_cool_fn = btm_param->btm_cool_fn; + adc_pmic->batt.btm_cool_fn = btm_param->btm_cool_fn; } if (btm_param->btm_warm_fn != NULL) { @@ -874,7 +874,7 @@ uint32_t pm8xxx_adc_btm_configure(struct pm8xxx_adc_arb_btm_param *btm_param) if (rc < 0) goto write_err; - adc_pmic->batt->btm_warm_fn = btm_param->btm_warm_fn; + adc_pmic->batt.btm_warm_fn = btm_param->btm_warm_fn; } rc = pm8xxx_adc_read_reg(PM8XXX_ADC_ARB_BTM_CNTRL1, &arb_btm_cntrl1); @@ -952,10 +952,10 @@ static uint32_t pm8xxx_adc_btm_read(uint32_t channel) if (rc < 0) goto write_err; - if (pmic_adc->batt->btm_warm_fn != NULL) + if (pmic_adc->batt.btm_warm_fn != NULL) enable_irq(adc_pmic->btm_warm_irq); - if (pmic_adc->batt->btm_cool_fn != NULL) + if (pmic_adc->batt.btm_cool_fn != NULL) enable_irq(adc_pmic->btm_cool_irq); write_err: @@ -1159,7 +1159,6 @@ static int __devinit pm8xxx_adc_probe(struct platform_device *pdev) } adc_pmic = devm_kzalloc(&pdev->dev, sizeof(struct pm8xxx_adc) + - sizeof(struct pm8xxx_adc_arb_btm_param) + (sizeof(struct sensor_device_attribute) * pdata->adc_num_board_channel), GFP_KERNEL); if (!adc_pmic) {