Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c77eb3c authored by Kensuke Miyagi's avatar Kensuke Miyagi
Browse files

Fix deadlock between TRMS lock and Tuner.mLnbLock

Change it so that Lnb.close() only grabs TRMS lock when not called in
the resource reclaim flow.

Bug: 307907612
Test: TunerTest
Change-Id: Ib1a097f147a9dc9afce84015d237f8e1a7a96b91
parent 2853caae
Loading
Loading
Loading
Loading
+20 −16
Original line number Diff line number Diff line
@@ -264,6 +264,25 @@ public class Lnb implements AutoCloseable {
        }
    }

    /* package */ void closeInternal() {
        synchronized (mLock) {
            if (mIsClosed) {
                return;
            }
            int res = nativeClose();
            if (res != Tuner.RESULT_SUCCESS) {
                TunerUtils.throwExceptionForResult(res, "Failed to close LNB");
            } else {
                mIsClosed = true;
                if (mOwner != null) {
                    mOwner.releaseLnb();
                    mOwner = null;
                }
                mCallbackMap.clear();
            }
        }
    }

    /**
     * Sets the LNB's power voltage.
     *
@@ -330,22 +349,7 @@ public class Lnb implements AutoCloseable {
    public void close() {
        acquireTRMSLock("close()");
        try {
            synchronized (mLock) {
                if (mIsClosed) {
                    return;
                }
                int res = nativeClose();
                if (res != Tuner.RESULT_SUCCESS) {
                    TunerUtils.throwExceptionForResult(res, "Failed to close LNB");
                } else {
                    mIsClosed = true;
                    if (mOwner != null) {
                        mOwner.releaseLnb();
                        mOwner = null;
                    }
                    mCallbackMap.clear();
                }
            }
            closeInternal();
        } finally {
            releaseTRMSLock();
        }
+5 −4
Original line number Diff line number Diff line
@@ -914,7 +914,7 @@ public class Tuner implements AutoCloseable {
                if (DEBUG) {
                    Log.d(TAG, "calling mLnb.close() : " + mClientId);
                }
                mLnb.close();
                mLnb.closeInternal();
            } else {
                if (DEBUG) {
                    Log.d(TAG, "NOT calling mLnb.close() : " + mClientId);
@@ -2348,6 +2348,7 @@ public class Tuner implements AutoCloseable {
    @Nullable
    public Lnb openLnbByName(@NonNull String name, @CallbackExecutor @NonNull Executor executor,
            @NonNull LnbCallback cb) {
        acquireTRMSLock("openLnbByName");
        mLnbLock.lock();
        try {
            Objects.requireNonNull(name, "LNB name must not be null");
@@ -2356,7 +2357,7 @@ public class Tuner implements AutoCloseable {
            Lnb newLnb = nativeOpenLnbByName(name);
            if (newLnb != null) {
                if (mLnb != null) {
                    mLnb.close();
                    mLnb.closeInternal();
                    mLnbHandle = null;
                }
                mLnb = newLnb;
@@ -2367,6 +2368,7 @@ public class Tuner implements AutoCloseable {
            }
            return mLnb;
        } finally {
            releaseTRMSLock();
            mLnbLock.unlock();
        }
    }
@@ -2784,8 +2786,8 @@ public class Tuner implements AutoCloseable {
        }
    }

    // Must be called while TRMS lock is being held
    /* package */ void releaseLnb() {
        acquireTRMSLock("releaseLnb()");
        mLnbLock.lock();
        try {
            if (mLnbHandle != null) {
@@ -2802,7 +2804,6 @@ public class Tuner implements AutoCloseable {
            }
            mLnb = null;
        } finally {
            releaseTRMSLock();
            mLnbLock.unlock();
        }
    }