summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-28 05:41:05 -0700
committerLinus Groh <mail@linusgroh.de>2021-06-01 23:14:40 +0100
commit23c021912e3e550400d862de93cc152d5818a653 (patch)
tree2fc4c21fb56f833825886abb26e2dc30b1c13fd2
parent8f9872581b94761fe217b72add803f23dc27f571 (diff)
downloadserenity-23c021912e3e550400d862de93cc152d5818a653.zip
Kernel: Move TmpFS towards OOM safety
-rw-r--r--Kernel/FileSystem/TmpFS.cpp21
-rw-r--r--Kernel/FileSystem/TmpFS.h6
2 files changed, 15 insertions, 12 deletions
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp
index e56e310207..08cfb261bc 100644
--- a/Kernel/FileSystem/TmpFS.cpp
+++ b/Kernel/FileSystem/TmpFS.cpp
@@ -11,9 +11,9 @@
namespace Kernel {
-NonnullRefPtr<TmpFS> TmpFS::create()
+RefPtr<TmpFS> TmpFS::create()
{
- return adopt_ref(*new TmpFS);
+ return adopt_ref_if_nonnull(new TmpFS);
}
TmpFS::TmpFS()
@@ -27,7 +27,7 @@ TmpFS::~TmpFS()
bool TmpFS::initialize()
{
m_root_inode = TmpFSInode::create_root(*this);
- return true;
+ return !m_root_inode.is_null();
}
NonnullRefPtr<Inode> TmpFS::root_inode() const
@@ -84,14 +84,15 @@ TmpFSInode::~TmpFSInode()
{
}
-NonnullRefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
+RefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
{
- auto inode = adopt_ref(*new TmpFSInode(fs, metadata, parent));
- fs.register_inode(inode);
+ auto inode = adopt_ref_if_nonnull(new TmpFSInode(fs, metadata, parent));
+ if (inode)
+ fs.register_inode(*inode);
return inode;
}
-NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs)
+RefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs)
{
InodeMetadata metadata;
auto now = kgettimeofday().to_truncated_seconds();
@@ -270,10 +271,12 @@ KResultOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(const String& name, mod
metadata.mtime = now;
auto child = TmpFSInode::create(fs(), metadata, identifier());
- auto result = add_child(child, name, mode);
+ if (!child)
+ return ENOMEM;
+ auto result = add_child(*child, name, mode);
if (result.is_error())
return result;
- return child;
+ return child.release_nonnull();
}
KResult TmpFSInode::add_child(Inode& child, const StringView& name, mode_t)
diff --git a/Kernel/FileSystem/TmpFS.h b/Kernel/FileSystem/TmpFS.h
index 0557e00286..823a21c33c 100644
--- a/Kernel/FileSystem/TmpFS.h
+++ b/Kernel/FileSystem/TmpFS.h
@@ -21,7 +21,7 @@ class TmpFS final : public FS {
public:
virtual ~TmpFS() override;
- static NonnullRefPtr<TmpFS> create();
+ static RefPtr<TmpFS> create();
virtual bool initialize() override;
virtual const char* class_name() const override { return "TmpFS"; }
@@ -74,8 +74,8 @@ public:
private:
TmpFSInode(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent);
- static NonnullRefPtr<TmpFSInode> create(TmpFS&, InodeMetadata metadata, InodeIdentifier parent);
- static NonnullRefPtr<TmpFSInode> create_root(TmpFS&);
+ static RefPtr<TmpFSInode> create(TmpFS&, InodeMetadata metadata, InodeIdentifier parent);
+ static RefPtr<TmpFSInode> create_root(TmpFS&);
void notify_watchers();