Skip to content

Upstream#39

Merged
NathanNeurotic merged 3 commits into
NathanNeurotic:masterfrom
ps2homebrew:master
May 19, 2026
Merged

Upstream#39
NathanNeurotic merged 3 commits into
NathanNeurotic:masterfrom
ps2homebrew:master

Conversation

@NathanNeurotic
Copy link
Copy Markdown
Owner

Pull Request

Summary

Provide a clear and concise description of the change.

  • What does this PR do?
  • Why is it necessary?
  • What problem does it solve?

Type of Change

Select all that apply:

  • Bug fix
  • Feature addition
  • Performance improvement
  • Refactor (non-functional change)
  • Documentation update
  • Breaking change
  • Other (explain below)

Related Issues

Link related issues using:

Closes #
Fixes #
Related to #


Scope

  • This PR contains a single logical change.
  • No unrelated refactoring is included.
  • No formatting-only noise is included.

If this PR modifies multiple subsystems, explain why that is necessary:


Technical Details

Describe:

  • What files are affected
  • What systems are impacted
  • Why this approach was chosen
  • Any alternative approaches considered

If modifying core logic, explain potential side effects.


Testing

  • Builds successfully
  • No new warnings introduced
  • Existing functionality tested
  • Regression risk evaluated
  • Tested on latest default branch

Describe how you tested this change:


Breaking Changes

If this is a breaking change, describe:

  • What breaks
  • Why it is justified
  • Migration path (if applicable)

If not applicable, state: "No breaking changes."


Security Considerations

Does this change affect:

  • Authentication
  • External inputs
  • File handling
  • Device access
  • Network behavior

If yes, explain impact.


Checklist

  • I have read CONTRIBUTING.md
  • I have followed the project code standards
  • I have rebased on the latest default branch
  • CI passes locally or via GitHub
  • This PR does not introduce hidden side effects

Additional Notes

Provide any additional context here.

@NathanNeurotic NathanNeurotic merged commit ea91db0 into NathanNeurotic:master May 19, 2026
19 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces ATA device readiness checks during driver initialization by adding ata_wait_for_busy_clear and ata_wait_for_ready functions. These are called within atad_start to ensure the hardware is ready before proceeding. Feedback identifies a critical issue where failing these checks leads to an error return without cleaning up previously registered resources (such as interrupt handlers and BDM connections), which could cause system crashes. Additionally, the review points out a logic error regarding the ATA specification for status register bits and requests that variable declarations be moved to the top of functions to maintain C89 compatibility.

Comment on lines +250 to +251
if (res < 0)
goto out;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This error path is critical. If atad_start returns a negative error code, the module may be unloaded, but several resources (interrupt handlers, power-off handler, semaphore, event flag, and BDM connection) have already been registered and are not cleaned up. This will cause a system crash when an interrupt occurs or during shutdown as the kernel attempts to call code in freed memory. Consider moving these readiness checks to the beginning of the function before resource allocation, or implementing a proper cleanup sequence.

Comment on lines +143 to +158
{
USE_ATA_REGS;

for (int waited = 0; waited < timeout; waited++) {
u8 status = ata_hwport->r_status;

if (!(status & ATA_STAT_BUSY) && (status & ATA_STAT_READY))
return 0;

if (status & ATA_STAT_ERR) {
M_PRINTF("ata_wait_for_ready ERR: status=0x%02x err=0x%02x\n", status, sceAtaGetError());
return ATA_RES_ERR_IO;
}

DelayThread(1000);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block has two issues:

  1. Logic Bug: Per the ATA specification, status register bits (including ERR) are indeterminate when the BUSY bit is set. Checking ATA_STAT_ERR while ATA_STAT_BUSY is active can lead to false failure reports. The error check should only occur when BUSY is 0.
  2. Style: The loop variable waited should be declared at the top of the function to match the project's C89 style.
{
    USE_ATA_REGS;
    int waited;
    u8 status;

    for (waited = 0; waited < timeout; waited++) {
        status = ata_hwport->r_status;

        if (!(status & ATA_STAT_BUSY)) {
            if (status & ATA_STAT_READY)
                return 0;

            if (status & ATA_STAT_ERR) {
                M_PRINTF("ata_wait_for_ready ERR: status=0x%02x err=0x%02x\n", status, sceAtaGetError());
                return ATA_RES_ERR_IO;
            }
        }

        DelayThread(1000);
    }

Comment on lines +128 to +131
{
USE_ATA_REGS;

for (int waited = 0; waited < timeout; waited++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable waited is declared inside the for loop, which is a C99 feature. To maintain consistency with the C89 style used throughout the rest of this file, please move the declaration to the top of the function.

Suggested change
{
USE_ATA_REGS;
for (int waited = 0; waited < timeout; waited++) {
{
USE_ATA_REGS;
int waited;
for (waited = 0; waited < timeout; waited++) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants