)]}'
{
  "commit": "a712f4aabd950a2b200ac2a36b944a0d57638b11",
  "tree": "a7dd3133457aa8a72991ebdc7fc4318f31e1bb7e",
  "parents": [
    "14ba19101734884dc040cbc20ab6f49ca9c47425"
  ],
  "author": {
    "name": "Ira Weiny",
    "email": "ira.weiny@intel.com",
    "time": "Wed Dec 20 16:17:35 2023 -0800"
  },
  "committer": {
    "name": "Shuo Yang",
    "email": "gshuoy@google.com",
    "time": "Fri Sep 06 16:31:07 2024 +0000"
  },
  "message": "PCI: Introduce cleanup helpers for device reference counts and locks\n\ncommit ced085ef369af7a2b6da962ec2fbd01339f60693 upstream.\n\nThe \"goto error\" pattern is notorious for introducing subtle resource\nleaks. Use the new cleanup.h helpers for PCI device reference counts and\nlocks.\n\nSimilar to the new put_device() and device_lock() cleanup helpers,\n__free(put_device) and guard(device), define the same for PCI devices,\n__free(pci_dev_put) and guard(pci_dev).  These helpers eliminate the\nneed for \"goto free;\" and \"goto unlock;\" patterns. For example, A\n\u0027struct pci_dev *\u0027 instance declared as:\n\n    struct pci_dev *pdev __free(pci_dev_put) \u003d NULL;\n\n...will automatically call pci_dev_put() if @pdev is non-NULL when @pdev\ngoes out of scope (automatic variable scope). If a function wants to\ninvoke pci_dev_put() on error, but return @pdev on success, it can do:\n\n    return no_free_ptr(pdev);\n\n...or:\n\n    return_ptr(pdev);\n\nFor potential cleanup opportunity there are 587 open-coded calls to\npci_dev_put() in the kernel with 65 instances within 10 lines of a goto\nstatement with the CXL driver threatening to add another one.\n\nThe guard() helper holds the associated lock for the remainder of the\ncurrent scope in which it was invoked. So, for example:\n\n    func(...)\n    {\n        if (...) {\n            ...\n            guard(pci_dev); /* pci_dev_lock() invoked here */\n            ...\n        } /* \u003c- implied pci_dev_unlock() triggered here */\n    }\n\nThere are 15 invocations of pci_dev_unlock() in the kernel with 5\ninstances within 10 lines of a goto statement. Again, the CXL driver is\nthreatening to add another.\n\nIntroduce these helpers to preclude the addition of new more error prone\ngoto put; / goto unlock; sequences. For now, these helpers are used in\ndrivers/cxl/pci.c to allow ACPI error reports to be fed back into the\nCXL driver associated with the PCI device identified in the report.\n\nBUG\u003db/362700136\nTEST\u003dpresubmit\nRELEASE_NOTE\u003dFixes CVE-2024-42302 in the Linux kernel\n\ncos-patch: security-high\nCc: Bjorn Helgaas \u003cbhelgaas@google.com\u003e\nChange-Id: Id61c2cb136205688cc9607842dbad2262c6169fd\nSigned-off-by: Ira Weiny \u003cira.weiny@intel.com\u003e\nLink: https://lore.kernel.org/r/20231220-cxl-cper-v5-8-1bb8a4ca2c7a@intel.com\n[djbw: rewrite changelog]\nAcked-by: Bjorn Helgaas \u003cbhelgaas@google.com\u003e\nReviewed-by: Jonathan Cameron \u003cJonathan.Cameron@huawei.com\u003e\nAcked-by: Ard Biesheuvel \u003cardb@kernel.org\u003e\nSigned-off-by: Dan Williams \u003cdan.j.williams@intel.com\u003e\nSigned-off-by: Lukas Wunner \u003clukas@wunner.de\u003e\nSigned-off-by: Greg Kroah-Hartman \u003cgregkh@linuxfoundation.org\u003e\nReviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/80183\nTested-by: Cusky Presubmit Bot \u003cpresubmit@cos-infra-prod.iam.gserviceaccount.com\u003e\nReviewed-by: Anil Altinay \u003caaltinay@google.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "4da7411da9baf5dcaa79d3ebc15d8adba171c88e",
      "old_mode": 33188,
      "old_path": "include/linux/pci.h",
      "new_id": "df73fb26b8250f0cfe45b3b0a8e5ca3a7bc9ef32",
      "new_mode": 33188,
      "new_path": "include/linux/pci.h"
    }
  ]
}
