Repository: libsdl-org/SDL
File: src/joystick/linux/SDL_sysjoystick.c (C)

Code before:
    if (!item) {
        return SDL_SetError("No such device");
    }

    joystick->hwdata = (struct joystick_hwdata *)
        SDL_calloc(1, sizeof(*joystick->hwdata));
    if (!joystick->hwdata) {
        return false;
    }

    item_sensor = GetSensor(item);
    if (!PrepareJoystickHwdata(joystick, item, item_sensor)) {
        SDL_free(joystick->hwdata);
        joystick->hwdata = NULL;
        return false; // SDL_SetError will already have been called
    }

    SDL_assert(item->hwdata == NULL);
    SDL_assert(!item_sensor || item_sensor->hwdata == NULL);
    item->hwdata = joystick->hwdata;
    if (item_sensor) {
        item_sensor->hwdata = joystick->hwdata;
    }

    const char *serial = NULL;
    if (SDL_UDEV_GetProductSerial(item->path, &serial) {
        joystick->serial = SDL_strdup(serial);
    }

    // mark joystick as fresh and ready
    joystick->hwdata->fresh = true;

    if (joystick->hwdata->has_gyro) {
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f);
    }
    if (joystick->hwdata->has_accelerometer) {
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 0.0f);
    }
    if (joystick->hwdata->fd_sensor >= 0) {
        // Don't keep fd_sensor opened while sensor is disabled
        close(joystick->hwdata->fd_sensor);
        joystick->hwdata->fd_sensor = -1;
    }

    if (joystick->hwdata->ff_rumble || joystick->hwdata->ff_sine) {
        SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true);
    }
    return true;
}

static bool LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)

Review comment (suggestion):
```suggestion
    if (SDL_UDEV_GetProductSerial(item->path, &serial)) {
```

Code after:
    if (!item) {
        return SDL_SetError("No such device");
    }

    joystick->hwdata = (struct joystick_hwdata *)
        SDL_calloc(1, sizeof(*joystick->hwdata));
    if (!joystick->hwdata) {
        return false;
    }

    item_sensor = GetSensor(item);
    if (!PrepareJoystickHwdata(joystick, item, item_sensor)) {
        SDL_free(joystick->hwdata);
        joystick->hwdata = NULL;
        return false; // SDL_SetError will already have been called
    }

    SDL_assert(item->hwdata == NULL);
    SDL_assert(!item_sensor || item_sensor->hwdata == NULL);
    item->hwdata = joystick->hwdata;
    if (item_sensor) {
        item_sensor->hwdata = joystick->hwdata;
    }

#ifdef SDL_USE_LIBUDEV
    const char *serial = NULL;
    if (SDL_UDEV_GetProductSerial(item->path, &serial)) {
        joystick->serial = SDL_strdup(serial);
    }
#endif

    // mark joystick as fresh and ready
    joystick->hwdata->fresh = true;

    if (joystick->hwdata->has_gyro) {
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f);
    }
    if (joystick->hwdata->has_accelerometer) {
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 0.0f);
    }
    if (joystick->hwdata->fd_sensor >= 0) {
        // Don't keep fd_sensor opened while sensor is disabled
        close(joystick->hwdata->fd_sensor);
        joystick->hwdata->fd_sensor = -1;
    }

    if (joystick->hwdata->ff_rumble || joystick->hwdata->ff_sine) {
        SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true);
    }
    return true;
}