Thanks Shannon!

Todd Fujinaka
Software Application Engineer
Data Center Group
Intel Corporation
todd.fujin...@intel.com

-----Original Message-----
From: Shannon Nelson <snel...@pensando.io> 
Sent: Tuesday, March 9, 2021 3:28 PM
To: e1000-devel@lists.sourceforge.net
Subject: [E1000-devel] kcompat landmine - devm_kcalloc

Hi folks,

I just spent a very long time debugging a random kernel panic that was coming 
from some sort of memory scribbling in our ionic driver, and found the culprit 
in the kcompat.h code that we've borrowed from Intel drivers.  I thought I'd 
let you know before someone else hit this. You'll probably want to check this 
in all your out-of-tree drivers.

Thanks for making this chunk of code available to the world.  Here's the world 
giving back to you.

Cheers,
sln



kcompat: add parens to devm_kcalloc macro

     The macro in kcompat for devm_kcalloc() uses its parameters in
     a multiplication in a call to devm_kzalloc(), but didn't protect
     those parameters with ()'s.  This caused havoc and several days
     debugging a random kernel panic when one parameter was essentially
     a + b: the resulting order of operations didn't allocate the
     expected amount of memory and we ended up scribbling over random
     other objects, causing great pain, chaos, and gnashing of teeth.

     Signed-off-by: Shannon Nelson <snel...@pensando.io>

diff --git a/platform/drivers/linux/eth/ionic/kcompat.h
b/platform/drivers/linux/eth/ionic/kcompat.h
index 12c4361d2a..a87428b4e6 100644
--- a/platform/drivers/linux/eth/ionic/kcompat.h
+++ b/platform/drivers/linux/eth/ionic/kcompat.h
@@ -5003,7 +5003,7 @@ static inline struct pci_dev *pci_upstream_bridge(struct 
pci_dev *dev)

  #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,20) )
  #define devm_kcalloc(dev, cnt, size, flags) \
-       devm_kzalloc(dev, cnt * size, flags)
+       devm_kzalloc(dev, (cnt) * (size), flags)
  #endif /* > 2.6.20 */

  #if (!(RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7,2)))



_______________________________________________
E1000-devel mailing list
E1000-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel Ethernet, visit 
https://forums.intel.com/s/topic/0TO0P00000018NbWAI/intel-ethernet

_______________________________________________
E1000-devel mailing list
E1000-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel Ethernet, visit 
https://forums.intel.com/s/topic/0TO0P00000018NbWAI/intel-ethernet

Reply via email to