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

Code before:
        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)
{
    struct input_event event;

    SDL_AssertJoysticksLocked();


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

Code after:
        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;
}

static bool LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
    struct input_event event;