Skip to contentSkip to conversation

MFD: pcf50633: Fixes and updates

PATCH In review Lars-Peter Clausen 2 participants 6 messages May 12, 2010 – May 16, 2010 Multifunction devices (MFD)

lore
Share & tools
lore
#0 lore raw

cover MFD: pcf50633: Fixes and updates

Hi

This patch series contains fixes and updates for the pcf50633 mfd and adc driver.

Lars-Peter Clausen (4):
MFD: pcf50633: Fix bitfield logic in interrupt handler
MFD: pcf50633-adc: Fix potential race pcf50633_adc_sync_read
MFD: pcf50633: Use threaded irq
MFD: pcf50633: Move irq related functions to its own file.

 drivers/mfd/Makefile        |    3 +-
 drivers/mfd/pcf50633-adc.c  |   39 ++---
 drivers/mfd/pcf50633-core.c |  344 ++-----------------------------------------
 drivers/mfd/pcf50633-irq.c  |  318 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 346 insertions(+), 358 deletions(-)
 create mode 100644 drivers/mfd/pcf50633-irq.c
#1 lore raw

PATCH 1/4 MFD: pcf50633: Fix bitfield logic in interrupt handler

Those constants are alreay bitfields.

---
 drivers/mfd/pcf50633-core.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/mfd/pcf50633-core.c +4 -4
index d66f389..6f7fb60 100644
@@ -354,18 +354,18 @@ static void pcf50633_irq_worker(struct work_struct *work)
 	if (pcf_int[0] & (PCF50633_INT1_USBINS | PCF50633_INT1_USBREM)) {
 		chgstat = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
 		if (chgstat & (0x3 << 4))
-			pcf_int[0] &= ~(1 << PCF50633_INT1_USBREM);
+			pcf_int[0] &= ~PCF50633_INT1_USBREM;
 		else
-			pcf_int[0] &= ~(1 << PCF50633_INT1_USBINS);
+			pcf_int[0] &= ~PCF50633_INT1_USBINS;
 	}
 
 	/* Make sure only one of ADPINS or ADPREM is set */
 	if (pcf_int[0] & (PCF50633_INT1_ADPINS | PCF50633_INT1_ADPREM)) {
 		chgstat = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
 		if (chgstat & (0x3 << 4))
-			pcf_int[0] &= ~(1 << PCF50633_INT1_ADPREM);
+			pcf_int[0] &= ~PCF50633_INT1_ADPREM;
 		else
-			pcf_int[0] &= ~(1 << PCF50633_INT1_ADPINS);
+			pcf_int[0] &= ~PCF50633_INT1_ADPINS;
 	}
 
 	dev_dbg(pcf->dev, "INT1=0x%02x INT2=0x%02x INT3=0x%02x "
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH 2/4 MFD: pcf50633-adc: Fix potential race pcf50633_adc_sync_read

Currently it's not guaranteed that request struct is not already freed when reading from it. Fix this by moving synced request related fields from the pcf50633_adc_request struct to its own struct and store it on the functions stack.

---
 drivers/mfd/pcf50633-adc.c |   39 +++++++++++++++------------------------
 1 files changed, 15 insertions(+), 24 deletions(-)
drivers/mfd/pcf50633-adc.c +15 -24
index fe8f922..aed0d2a 100644
@@ -30,13 +30,13 @@
 struct pcf50633_adc_request {
 	int mux;
 	int avg;
-	int result;
 	void (*callback)(struct pcf50633 *, void *, int);
 	void *callback_param;
+};
 
-	/* Used in case of sync requests */
+struct pcf50633_adc_sync_request {
+	int result;
 	struct completion completion;
-
 };
 
 #define PCF50633_MAX_ADC_FIFO_DEPTH 8
@@ -109,10 +109,10 @@ adc_enqueue_request(struct pcf50633 *pcf, struct pcf50633_adc_request *req)
 	return 0;
 }
 
-static void
-pcf50633_adc_sync_read_callback(struct pcf50633 *pcf, void *param, int result)
+static void pcf50633_adc_sync_read_callback(struct pcf50633 *pcf, void *param,
+	int result)
 {
-	struct pcf50633_adc_request *req = param;
+	struct pcf50633_adc_sync_request *req = param;
 
 	req->result = result;
 	complete(&req->completion);
@@ -120,28 +120,19 @@ pcf50633_adc_sync_read_callback(struct pcf50633 *pcf, void *param, int result)
 
 int pcf50633_adc_sync_read(struct pcf50633 *pcf, int mux, int avg)
 {
-	struct pcf50633_adc_request *req;
-	int err;
+	struct pcf50633_adc_sync_request req;
+	int ret;
 
-	/* req is freed when the result is ready, in interrupt handler */
-	req = kzalloc(sizeof(*req), GFP_KERNEL);
-	if (!req)
-		return -ENOMEM;
-
-	req->mux = mux;
-	req->avg = avg;
-	req->callback =  pcf50633_adc_sync_read_callback;
-	req->callback_param = req;
+	init_completion(&req.completion);
 
-	init_completion(&req->completion);
-	err = adc_enqueue_request(pcf, req);
-	if (err)
-		return err;
+	ret = pcf50633_adc_async_read(pcf, mux, avg,
+		pcf50633_adc_sync_read_callback, &req);
+	if (ret)
+		return ret;
 
-	wait_for_completion(&req->completion);
+	wait_for_completion(&req.completion);
 
-	/* FIXME by this time req might be already freed */
-	return req->result;
+	return req.result;
 }
 EXPORT_SYMBOL_GPL(pcf50633_adc_sync_read);
 
Signature · 1 line
1.5.6.5
#3 lore raw

PATCH 3/4 MFD: pcf50633: Use threaded irq

Use threaded oneshot irq handler instead of normal irq handler and a workqueue.

---
 drivers/mfd/Makefile        |    2 +-
 drivers/mfd/pcf50633-core.c |   57 +++++++------------------------------------
 2 files changed, 10 insertions(+), 49 deletions(-)
drivers/mfd/Makefile +1 -1
index 4c684c1..8593496 100644
@@ -57,7 +57,7 @@ obj-$(CONFIG_PMIC_DA903X)	+= da903x.o
 max8925-objs			:= max8925-core.o max8925-i2c.o
 obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 
-obj-$(CONFIG_MFD_PCF50633)	+= pcf50633-core.o
+obj-$(CONFIG_MFD_PCF50633)	+= pcf50633-core.o pcf50633-irq.o
 obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
 obj-$(CONFIG_PCF50633_GPIO)	+= pcf50633-gpio.o
 obj-$(CONFIG_ABX500_CORE)	+= abx500-core.o
drivers/mfd/pcf50633-core.c +9 -48

118 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#4 lore raw

PATCH 4/4 MFD: pcf50633: Move irq related functions to its own file.

This reduces code clutter a bit and will ease an migration to genirq.

---
 drivers/mfd/Makefile        |    3 +-
 drivers/mfd/pcf50633-core.c |  303 ++---------------------------------------
 drivers/mfd/pcf50633-irq.c  |  318 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 330 insertions(+), 294 deletions(-)
 create mode 100644 drivers/mfd/pcf50633-irq.c
drivers/mfd/Makefile +2 -1
index 8593496..ca1517e 100644
@@ -57,7 +57,8 @@ obj-$(CONFIG_PMIC_DA903X)	+= da903x.o
 max8925-objs			:= max8925-core.o max8925-i2c.o
 obj-$(CONFIG_MFD_MAX8925)	+= max8925.o
 
-obj-$(CONFIG_MFD_PCF50633)	+= pcf50633-core.o pcf50633-irq.o
+pcf50633-objs			:= pcf50633-core.o pcf50633-irq.o
+obj-$(CONFIG_MFD_PCF50633)	+= pcf50633.o
 obj-$(CONFIG_PCF50633_ADC)	+= pcf50633-adc.o
 obj-$(CONFIG_PCF50633_GPIO)	+= pcf50633-gpio.o
 obj-$(CONFIG_ABX500_CORE)	+= abx500-core.o
drivers/mfd/pcf50633-core.c +10 -293

358 lines not on this page · raw message

drivers/mfd/pcf50633-irq.c new file +318 -0

318 lines not on this page · raw message

Signature · 1 line
1.5.6.5
#5 lore raw
In reply to Lars-Peter Clausen

Hi Lars-Peter,

Quoted 4 lines · Lars-Peter Clausen

Hi

This patch series contains fixes and updates for the pcf50633 mfd and adc driver.

All 4 patches applied, thanks a lot.

Cheers,
Samuel.

Quoted 13 lines

Lars-Peter Clausen (4):
MFD: pcf50633: Fix bitfield logic in interrupt handler
MFD: pcf50633-adc: Fix potential race pcf50633_adc_sync_read
MFD: pcf50633: Use threaded irq
MFD: pcf50633: Move irq related functions to its own file.

 drivers/mfd/Makefile        |    3 +-
 drivers/mfd/pcf50633-adc.c  |   39 ++---
 drivers/mfd/pcf50633-core.c |  344 ++-----------------------------------------
 drivers/mfd/pcf50633-irq.c  |  318 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 346 insertions(+), 358 deletions(-)
 create mode 100644 drivers/mfd/pcf50633-irq.c
Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/