X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/eb6b6ca394357805f2bdba989abae309f718b4d8..f427ee49d309d8fc33ebf3042c3a775f2f530ded:/iokit/Kernel/IOStateReporter.cpp diff --git a/iokit/Kernel/IOStateReporter.cpp b/iokit/Kernel/IOStateReporter.cpp index 4380c6cf2..44dd5c18d 100644 --- a/iokit/Kernel/IOStateReporter.cpp +++ b/iokit/Kernel/IOStateReporter.cpp @@ -26,6 +26,9 @@ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ +#define IOKIT_ENABLE_SHARED_PTR + +#include <libkern/c++/OSSharedPtr.h> #include <IOKit/IOKernelReportStructs.h> #include <IOKit/IOKernelReporters.h> #include "IOReporterDefs.h" @@ -36,34 +39,28 @@ OSDefineMetaClassAndStructors(IOStateReporter, IOReporter); /* static */ -IOStateReporter* +OSSharedPtr<IOStateReporter> IOStateReporter::with(IOService *reportingService, IOReportCategories categories, int nstates, IOReportUnit unit /* = kIOReportUnitHWTicks*/) { - IOStateReporter *reporter, *rval = NULL; - - // kprintf("%s\n", __func__); // can't IORLOG() from static + OSSharedPtr<IOStateReporter> reporter; - reporter = new IOStateReporter; - if (!reporter) { - goto finish; + if (nstates > INT16_MAX) { + return nullptr; } - if (!reporter->initWith(reportingService, categories, nstates, unit)) { - goto finish; + reporter = OSMakeShared<IOStateReporter>(); + if (!reporter) { + return nullptr; } - // success - rval = reporter; - -finish: - if (!rval) { - OSSafeReleaseNULL(reporter); + if (!reporter->initWith(reportingService, categories, (int16_t) nstates, unit)) { + return nullptr; } - return rval; + return reporter; } bool