Can someone explain if this wiring is correct
The details of this answer assume you are in North America. If you are elsewhere, you should add that information to your question.
Assuming you are correct in the wiring, then no, it is neither legal nor safe currently, though if the wiring is old enough, it may have been &quot;normal&quot; at the time.
The problem is that the switch is interrupting the neutral wire to the light while the hot wire goes directly to the light. The problem is that if you turn off the switch and go to work on the light without flipping the breaker (a bad idea but some people just depend on the switch), you can get shocked as the red wire to the light is still hot.
It should be very little effort to change the wiring so that the switch interrupts the hot instead. Also, on the white wire coming back from the switch, you should add a wrap of black tape or paint at each end to mark it as (switched) hot.