久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

linux內(nèi)核的內(nèi)存分配函數(shù)...

 昵稱3554661 2021-06-01

作用

函數(shù) devm_kzalloc() 和kzalloc()一樣都是內(nèi)核內(nèi)存分配函數(shù),但是devm_kzalloc()是跟設(shè)備(device)有關(guān)的,,

當(dāng)設(shè)備(device)被detached或者驅(qū)動(driver)卸載(unloaded)時,,內(nèi)存會被自動釋放。另外,,也可以通過函數(shù)

devm_kfree()手動釋放,。

    而kzalloc()則需要手動釋放(使用kfree()),但如果工程師檢查不仔細(xì),,則有可能造成內(nèi)存泄漏,。

格式

static inline void * devm_kzalloc(struct device * dev,,size_t size,gfp_t gfp)

{

    return devm_kmalloc(dev,,size,,gfp | __GFP_ZERO);                                                                                                                                                         

}

void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)                                                                                                                                               

{

    struct devres *dr;

     

    dr = alloc_dr(devm_kmalloc_release, size, gfp, dev_to_node(dev));

    if (unlikely(!dr))

        return NULL;

    set_node_dbginfo(&dr->node, "devm_kzalloc_release", size);

    devres_add(dev, dr->data);

    return dr->data;

}

EXPORT_SYMBOL_GPL(devm_kmalloc);

void devm_kfree(struct device * dev,void * p)                                                                                                                                                                  

{

    int rc;

    rc = devres_destroy(dev,,devm_kmalloc_release,,devm_kmalloc_match,p);

    WARN_ON(RC);

}

EXPORT_SYMBOL_GPL(devm_kfree);

示例

struct s3c2440_i2c_dev {

  struct device *dev;

  void __iomem *base;

  struct i2c_msg *msg;

  u32  frequency;

  int speed_mode;

  int slave_addr;

  struct i2c_adapter  adap;

};

static int s3c2440_i2c_probe(struct platform_device *pdev)

{

  struct s3c2440_i2c_dev *i2c_dev;

  struct i2c_adapter *adap;

  struct device *dev = &pdev->dev;

  struct resource *res;

  i2c_dev = devm_kzalloc(&pdev->dev, sizeof(struct s3c2440_i2c_dev), GFP_KERNEL);

  if(!i2c_dev)

  return -ENOMEM;

 

  ...

}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點擊一鍵舉報,。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多