ams: globally prefer R_RETURN to return for ams::Result

This commit is contained in:
Michael Scire 2022-03-26 14:48:33 -07:00
parent dd78ede99f
commit bbf22b4c60
325 changed files with 1955 additions and 1993 deletions

View file

@ -192,7 +192,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
}
/* Send the data. */
return this->Send(static_cast<const u8 *>(src), src_size, option, device->GetAddress(), device->GetAddressingMode());
R_RETURN(this->Send(static_cast<const u8 *>(src), src_size, option, device->GetAddress(), device->GetAddressingMode()));
}
Result I2cBusAccessor::Receive(void *dst, size_t dst_size, I2cDeviceProperty *device, TransactionOption option) {
@ -208,7 +208,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
}
/* Send the data. */
return this->Receive(static_cast<u8 *>(dst), dst_size, option, device->GetAddress(), device->GetAddressingMode());
R_RETURN(this->Receive(static_cast<u8 *>(dst), dst_size, option, device->GetAddress(), device->GetAddressingMode()));
}
void I2cBusAccessor::SuspendBus() {
@ -399,7 +399,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return i2c::ResultTimeout();
R_THROW(i2c::ResultTimeout());
}
/* Check and handle any errors. */
@ -429,7 +429,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return i2c::ResultTimeout();
R_THROW(i2c::ResultTimeout());
}
}
@ -474,7 +474,7 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return i2c::ResultTimeout();
R_THROW(i2c::ResultTimeout());
}
/* Check and handle any errors. */

View file

@ -101,13 +101,13 @@ namespace ams::i2c::driver::board::nintendo::nx::impl {
Result CheckAndHandleError() {
const Result result = this->GetTransactionResult();
this->HandleTransactionError(result);
if (R_FAILED(result)) {
this->DisableInterruptMask();
os::ClearInterruptEvent(std::addressof(m_interrupt_event));
return result;
}
R_SUCCEED();
R_RETURN(result);
}
public:
virtual void InitializeDriver() override;

View file

@ -27,14 +27,10 @@ namespace ams::i2c::driver {
Result OpenSessionImpl(I2cSession *out, I2cDeviceProperty *device) {
/* Construct the session. */
auto *session = std::construct_at(std::addressof(impl::GetI2cSessionImpl(*out)), DefaultRetryCount, DefaultRetryInterval);
auto session_guard = SCOPE_GUARD { std::destroy_at(session); };
ON_RESULT_FAILURE { std::destroy_at(session); };
/* Open the session. */
R_TRY(session->Open(device, ddsf::AccessMode_ReadWrite));
/* We succeeded. */
session_guard.Cancel();
R_SUCCEED();
R_RETURN(session->Open(device, ddsf::AccessMode_ReadWrite));
}
}
@ -48,9 +44,7 @@ namespace ams::i2c::driver {
AMS_ASSERT(device != nullptr);
/* Open the session. */
R_TRY(OpenSessionImpl(out, device));
R_SUCCEED();
R_RETURN(OpenSessionImpl(out, device));
}
void CloseSession(I2cSession &session) {
@ -61,14 +55,14 @@ namespace ams::i2c::driver {
AMS_ASSERT(src != nullptr);
AMS_ABORT_UNLESS(src_size > 0);
return impl::GetOpenI2cSessionImpl(session).Send(src, src_size, option);
R_RETURN(impl::GetOpenI2cSessionImpl(session).Send(src, src_size, option));
}
Result Receive(void *dst, size_t dst_size, I2cSession &session, TransactionOption option) {
AMS_ASSERT(dst != nullptr);
AMS_ABORT_UNLESS(dst_size > 0);
return impl::GetOpenI2cSessionImpl(session).Receive(dst, dst_size, option);
R_RETURN(impl::GetOpenI2cSessionImpl(session).Receive(dst, dst_size, option));
}
Result ExecuteCommandList(void *dst, size_t dst_size, I2cSession &session, const void *src, size_t src_size) {
@ -78,14 +72,14 @@ namespace ams::i2c::driver {
AMS_ABORT_UNLESS(src_size > 0);
AMS_ABORT_UNLESS(dst_size > 0);
return impl::GetOpenI2cSessionImpl(session).ExecuteCommandList(dst, dst_size, src, src_size);
R_RETURN(impl::GetOpenI2cSessionImpl(session).ExecuteCommandList(dst, dst_size, src, src_size));
}
Result SetRetryPolicy(I2cSession &session, int max_retry_count, int retry_interval_us) {
AMS_ASSERT(max_retry_count > 0);
AMS_ASSERT(retry_interval_us > 0);
return impl::GetOpenI2cSessionImpl(session).SetRetryPolicy(max_retry_count, retry_interval_us);
R_RETURN(impl::GetOpenI2cSessionImpl(session).SetRetryPolicy(max_retry_count, retry_interval_us));
}
}

View file

@ -28,7 +28,7 @@ namespace ams::i2c::driver {
}
Result RegisterDeviceCode(DeviceCode device_code, I2cDeviceProperty *device) {
return impl::RegisterDeviceCode(device_code, device);
R_RETURN(impl::RegisterDeviceCode(device_code, device));
}
bool UnregisterDeviceCode(DeviceCode device_code) {

View file

@ -148,7 +148,7 @@ namespace ams::i2c::driver::impl {
os::SleepThread(m_retry_interval);
continue;
}
return i2c::ResultBusBusy();
R_THROW(i2c::ResultBusBusy());
}
} R_END_TRY_CATCH;
@ -160,14 +160,14 @@ namespace ams::i2c::driver::impl {
/* Acquire exclusive access to the device. */
std::scoped_lock lk(this->GetDevice().SafeCastTo<I2cDeviceProperty>().GetDriver().SafeCastTo<II2cDriver>().GetTransactionOrderMutex());
return this->ExecuteTransactionWithRetry(nullptr, Command::Send, src, src_size, option);
R_RETURN(this->ExecuteTransactionWithRetry(nullptr, Command::Send, src, src_size, option));
}
Result I2cSessionImpl::Receive(void *dst, size_t dst_size, TransactionOption option) {
/* Acquire exclusive access to the device. */
std::scoped_lock lk(this->GetDevice().SafeCastTo<I2cDeviceProperty>().GetDriver().SafeCastTo<II2cDriver>().GetTransactionOrderMutex());
return this->ExecuteTransactionWithRetry(dst, Command::Receive, nullptr, dst_size, option);
R_RETURN(this->ExecuteTransactionWithRetry(dst, Command::Receive, nullptr, dst_size, option));
}
Result I2cSessionImpl::ExecuteCommandList(void *dst, size_t dst_size, const void *src, size_t src_size) {

View file

@ -130,20 +130,20 @@ namespace ams::i2c {
Result Send(const I2cSession &session, const void *src, size_t src_size, TransactionOption option) {
const ams::sf::InAutoSelectBuffer buf(src, src_size);
return GetInterface(session)->Send(buf, option);
R_RETURN(GetInterface(session)->Send(buf, option));
}
Result Receive(void *dst, size_t dst_size, const I2cSession &session, TransactionOption option) {
const ams::sf::OutAutoSelectBuffer buf(dst, dst_size);
return GetInterface(session)->Receive(buf, option);
R_RETURN(GetInterface(session)->Receive(buf, option));
}
Result ExecuteCommandList(void *dst, size_t dst_size, const I2cSession &session, const void *src, size_t src_size) {
const ams::sf::OutAutoSelectBuffer buf(dst, dst_size);
const ams::sf::InPointerArray<i2c::I2cCommand> arr(static_cast<const i2c::I2cCommand *>(src), src_size);
return GetInterface(session)->ExecuteCommandList(buf, arr);
R_RETURN(GetInterface(session)->ExecuteCommandList(buf, arr));
}
void SetRetryPolicy(const I2cSession &session, int max_retry_count, int retry_interval_us) {

View file

@ -34,7 +34,7 @@ namespace ams::i2c::server {
}
Result ManagerImpl::OpenSession(ams::sf::Out<ams::sf::SharedPointer<i2c::sf::ISession>> out, i2c::I2cDevice device) {
return this->OpenSession2(out, ConvertToDeviceCode(device));
R_RETURN(this->OpenSession2(out, ConvertToDeviceCode(device)));
}
Result ManagerImpl::HasDevice(ams::sf::Out<bool> out, i2c::I2cDevice device) {

View file

@ -44,31 +44,31 @@ namespace ams::i2c::server {
public:
/* Actual commands. */
Result SendOld(const ams::sf::InBuffer &in_data, i2c::TransactionOption option) {
return i2c::driver::Send(m_internal_session, in_data.GetPointer(), in_data.GetSize(), option);
R_RETURN(i2c::driver::Send(m_internal_session, in_data.GetPointer(), in_data.GetSize(), option));
}
Result ReceiveOld(const ams::sf::OutBuffer &out_data, i2c::TransactionOption option) {
return i2c::driver::Receive(out_data.GetPointer(), out_data.GetSize(), m_internal_session, option);
R_RETURN(i2c::driver::Receive(out_data.GetPointer(), out_data.GetSize(), m_internal_session, option));
}
Result ExecuteCommandListOld(const ams::sf::OutBuffer &rcv_buf, const ams::sf::InPointerArray<i2c::I2cCommand> &command_list){
return i2c::driver::ExecuteCommandList(rcv_buf.GetPointer(), rcv_buf.GetSize(), m_internal_session, command_list.GetPointer(), command_list.GetSize() * sizeof(i2c::I2cCommand));
R_RETURN(i2c::driver::ExecuteCommandList(rcv_buf.GetPointer(), rcv_buf.GetSize(), m_internal_session, command_list.GetPointer(), command_list.GetSize() * sizeof(i2c::I2cCommand)));
}
Result Send(const ams::sf::InAutoSelectBuffer &in_data, i2c::TransactionOption option) {
return i2c::driver::Send(m_internal_session, in_data.GetPointer(), in_data.GetSize(), option);
R_RETURN(i2c::driver::Send(m_internal_session, in_data.GetPointer(), in_data.GetSize(), option));
}
Result Receive(const ams::sf::OutAutoSelectBuffer &out_data, i2c::TransactionOption option) {
return i2c::driver::Receive(out_data.GetPointer(), out_data.GetSize(), m_internal_session, option);
R_RETURN(i2c::driver::Receive(out_data.GetPointer(), out_data.GetSize(), m_internal_session, option));
}
Result ExecuteCommandList(const ams::sf::OutAutoSelectBuffer &rcv_buf, const ams::sf::InPointerArray<i2c::I2cCommand> &command_list) {
return i2c::driver::ExecuteCommandList(rcv_buf.GetPointer(), rcv_buf.GetSize(), m_internal_session, command_list.GetPointer(), command_list.GetSize() * sizeof(i2c::I2cCommand));
R_RETURN(i2c::driver::ExecuteCommandList(rcv_buf.GetPointer(), rcv_buf.GetSize(), m_internal_session, command_list.GetPointer(), command_list.GetSize() * sizeof(i2c::I2cCommand)));
}
Result SetRetryPolicy(s32 max_retry_count, s32 retry_interval_us) {
return i2c::driver::SetRetryPolicy(m_internal_session, max_retry_count, retry_interval_us);
R_RETURN(i2c::driver::SetRetryPolicy(m_internal_session, max_retry_count, retry_interval_us));
}
};
static_assert(i2c::sf::IsISession<SessionImpl>);