You could simply turn on
// If enabled, axes won't move below MIN_POS in response to movement commands.
#define MIN_SOFTWARE_ENDSTOPS
// If enabled, axes won't move above MAX_POS in response to movement commands.
#define MAX_SOFTWARE_ENDSTOPS
But you really should turn of MIN_SOFTWARE_ENDSTOPS if you want to run a Mesh Based Bed Leveling System.
// If enabled, axes won't move below MIN_POS in response to movement commands.
#define MIN_SOFTWARE_ENDSTOPS
// If enabled, axes won't move above MAX_POS in response to movement commands.
#define MAX_SOFTWARE_ENDSTOPS
But you really should turn of MIN_SOFTWARE_ENDSTOPS if you want to run a Mesh Based Bed Leveling System.