]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOStateReporter.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / iokit / Kernel / IOStateReporter.cpp
index 4380c6cf21de1a87d86c2aee5116f8c939f5cea0..44dd5c18df7320cd19d1be6f89231cf7a5c2c17b 100644 (file)
@@ -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