diff mbox series

[2/3] staging: ccree: handle limiting of DMA masks

Message ID 1509450978-17784-3-git-send-email-gilad@benyossef.com
State New
Headers show
Series [1/3] staging: ccree: copy IV to DMAable memory | expand

Commit Message

Gilad Ben-Yossef Oct. 31, 2017, 11:56 a.m. UTC
Properly handle limiting of DMA masks based on device and bus
capabilities.

Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>

---
 drivers/staging/ccree/ssi_driver.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

-- 
2.7.4

Comments

Gilad Ben-Yossef Nov. 2, 2017, 7:28 a.m. UTC | #1
Hi,

Thank you for the review.

On Wed, Nov 1, 2017 at 1:09 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> On Tue, Oct 31, 2017 at 11:56:16AM +0000, Gilad Ben-Yossef wrote:

>>

>> -     if (!dev->coherent_dma_mask)

>> -             dev->coherent_dma_mask = DMA_BIT_MASK(DMA_BIT_MASK_LEN);

>> +     if (rc) {

>> +             dev_err(dev, "Error: failed in dma_set_mask, mask=%par\n",

>> +                     &dma_mask);

>> +             goto post_drvdata_err;

>

>

> Also this is not the right goto.  We should be turning the clk off.


Yes, it's wrong. I think a better thing to do though is to check the
DMA mask before turning the clock on, so the goto label
is right, but the code location is wrong...

>

> I don't really care for the naming scheme, and I know you renamed it for

> me already once and I feel bad for not liking it more.  It's still

> really a come-from label name and doesn't say what the goto does...

> Instead of post_clk_err, I wish it had names like "err_clk_off:".

>


> And in this case what it does is print a duplicative error message and

> return.  :/  The goto post_drvdata_err: lines should just print their

> own error messages if needed and return directly.  If there is no

> cleanup then there is no need for a goto.

>


Both good points. I will address them in a later patch.


> Anyway, that's not related to this patch.  Just resend it with

> goto post_clk_err: in the v2.


Will do.

Thanks!

Gilad


-- 
Gilad Ben-Yossef
Chief Coffee Drinker

"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
 -- Jean-Baptiste Queru
diff mbox series

Patch

diff --git a/drivers/staging/ccree/ssi_driver.c b/drivers/staging/ccree/ssi_driver.c
index 5f03c25..6d4269f 100644
--- a/drivers/staging/ccree/ssi_driver.c
+++ b/drivers/staging/ccree/ssi_driver.c
@@ -208,6 +208,7 @@  static int init_cc_resources(struct platform_device *plat_dev)
 	struct device *dev = &plat_dev->dev;
 	struct device_node *np = dev->of_node;
 	u32 signature_val;
+	dma_addr_t dma_mask;
 	int rc = 0;
 
 	new_drvdata = devm_kzalloc(dev, sizeof(*new_drvdata), GFP_KERNEL);
@@ -260,11 +261,24 @@  static int init_cc_resources(struct platform_device *plat_dev)
 	if (rc)
 		goto post_drvdata_err;
 
-	if (!dev->dma_mask)
-		dev->dma_mask = &dev->coherent_dma_mask;
+	if (!plat_dev->dev.dma_mask)
+		plat_dev->dev.dma_mask = &plat_dev->dev.coherent_dma_mask;
+
+	dma_mask = (dma_addr_t)(DMA_BIT_MASK(DMA_BIT_MASK_LEN));
+	while (dma_mask > 0x7fffffffUL) {
+		if (dma_supported(&plat_dev->dev, dma_mask)) {
+			rc = dma_set_coherent_mask(&plat_dev->dev, dma_mask);
+				if (!rc)
+					break;
+		}
+		dma_mask >>= 1;
+	}
 
-	if (!dev->coherent_dma_mask)
-		dev->coherent_dma_mask = DMA_BIT_MASK(DMA_BIT_MASK_LEN);
+	if (rc) {
+		dev_err(dev, "Error: failed in dma_set_mask, mask=%par\n",
+			&dma_mask);
+		goto post_drvdata_err;
+	}
 
 	/* Verify correct mapping */
 	signature_val = CC_HAL_READ_REGISTER(CC_REG_OFFSET(HOST_RGF, HOST_SIGNATURE));